3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Debug; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Debug\Exception\FlattenException; use Symfony\Component\Debug\Exception\OutOfMemoryException; if (!defined('ENT_SUBSTITUTE')) { define('ENT_SUBSTITUTE', 8); } /** * ExceptionHandler converts an exception to a Response object. * * It is mostly useful in debug mode to replace the default PHP/XDebug * output with something prettier and more useful. * * As this class is mainly used during Kernel boot, where nothing is yet * available, the Response content is always HTML. * * @author Fabien Potencier <fabien@symfony.com> */ class ExceptionHandler { private $debug; private $charset; private $handler; private $caughtOutput = 0; public function __construct($debug = true, $charset = 'UTF-8') { $this->debug = $debug; $this->charset = $charset; } /** * Registers the exception handler. * * @param bool $debug * * @return ExceptionHandler The registered exception handler */ public static function register($debug = true) { $handler = new static($debug); set_exception_handler(array($handler, 'handle')); return $handler; } /** * Sets a user exception handler. * * @param callable $handler An handler that will be called on Exception * * @return callable|null The previous exception handler if any */ public function setHandler($handler) { if (isset($handler) && !is_callable($handler)) { throw new \LogicException('The exception handler must be a valid PHP callable.'); } $old = $this->handler; $this->handler = $handler; return $old; } /** * {@inheritdoc} * * Sends a response for the given Exception. * * If you have the Symfony HttpFoundation component installed, * this method will use it to create and send the response. If not, * it will fallback to plain PHP functions. * * @see sendPhpResponse * @see createResponse */ public function handle(\Exception $exception) { if ($exception instanceof OutOfMemoryException) { $this->sendPhpResponse($exception); return; } // To be as fail-safe as possible, the exception is first handled // by our simple exception handler, then by the user exception handler. // The latter takes precedence and any output from the former is cancelled, // if and only if nothing bad happens in this handling path. $caughtOutput = 0; $this->caughtOutput = false; ob_start(array($this, 'catchOutput')); try { if (class_exists('Symfony\Component\HttpFoundation\Response')) { $response = $this->createResponse($exception); $response->sendHeaders(); $response->sendContent(); } else { $this->sendPhpResponse($exception); } } catch (\Exception $e) { // Ignore this $e exception, we have to deal with $exception } if (false === $this->caughtOutput) { ob_end_clean(); } if (isset($this->caughtOutput[0])) { ob_start(array($this, 'cleanOutput')); echo $this->caughtOutput; $caughtOutput = ob_get_length(); } $this->caughtOutput = 0; if (!empty($this->handler)) { try { call_user_func($this->handler, $exception); if ($caughtOutput) { $this->caughtOutput = $caughtOutput; } } catch (\Exception $e) { if (!$caughtOutput) { // All handlers failed. Let PHP handle that now. throw $exception; } } } } /** * Sends the error associated with the given Exception as a plain PHP response. * * This method uses plain PHP functions like header() and echo to output * the response. * * @param \Exception|FlattenException $exception An \Exception instance */ public function sendPhpResponse($exception) { echo $exception->getMessage(); } /** * @internal */ public function catchOutput($buffer) { $this->caughtOutput = $buffer; return ''; } /** * @internal */ public function cleanOutput($buffer) { if ($this->caughtOutput) { // use substr_replace() instead of substr() for mbstring overloading resistance $cleanBuffer = substr_replace($buffer, '', 0, $this->caughtOutput); if (isset($cleanBuffer[0])) { $buffer = $cleanBuffer; } } return $buffer; } } ExceptionHandler::register(); throw new \Exception('foo msg');

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.40.0040.01118.88
8.3.30.0030.01019.21
8.3.20.0070.00020.34
8.3.10.0040.00423.66
8.3.00.0040.00419.50
8.2.170.0060.00922.96
8.2.160.0070.01020.35
8.2.150.0110.00724.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0000.00822.14
8.2.110.0000.00920.93
8.2.100.0090.00617.78
8.2.90.0040.00418.34
8.2.80.0000.00820.38
8.2.70.0000.00817.63
8.2.60.0040.00418.05
8.2.50.0040.00418.07
8.2.40.0000.00820.07
8.2.30.0000.00718.23
8.2.20.0040.00417.92
8.2.10.0040.00418.19
8.2.00.0100.00017.93
8.1.270.0040.00423.96
8.1.260.0050.00326.35
8.1.250.0000.00828.09
8.1.240.0150.00322.16
8.1.230.0040.00721.16
8.1.220.0000.00817.90
8.1.210.0050.00519.15
8.1.200.0080.00417.47
8.1.190.0050.00317.36
8.1.180.0000.00818.10
8.1.170.0050.00518.82
8.1.160.0000.00821.94
8.1.150.0000.00918.70
8.1.140.0000.00817.43
8.1.130.0000.00717.88
8.1.120.0040.00417.52
8.1.110.0090.00017.42
8.1.100.0000.00717.50
8.1.90.0000.00817.44
8.1.80.0000.00817.54
8.1.70.0030.00317.40
8.1.60.0060.00317.63
8.1.50.0030.00617.61
8.1.40.0000.00817.59
8.1.30.0000.00817.66
8.1.20.0000.00817.69
8.1.10.0000.00817.64
8.1.00.0000.00917.59
8.0.300.0070.00020.21
8.0.290.0030.00616.88
8.0.280.0030.00318.49
8.0.270.0000.00717.32
8.0.260.0000.00617.40
8.0.250.0000.00717.09
8.0.240.0000.00717.05
8.0.230.0050.00316.98
8.0.220.0050.00316.97
8.0.210.0030.00316.93
8.0.200.0030.00317.05
8.0.190.0000.00817.13
8.0.180.0020.00517.01
8.0.170.0000.00817.05
8.0.160.0030.00316.89
8.0.150.0040.00417.03
8.0.140.0020.00516.95
8.0.130.0030.00313.54
8.0.120.0000.00916.95
8.0.110.0040.00416.87
8.0.100.0000.00717.05
8.0.90.0070.00016.90
8.0.80.0160.00716.97
8.0.70.0040.00416.96
8.0.60.0000.00817.13
8.0.50.0030.00516.90
8.0.30.0090.01217.36
8.0.20.0140.00617.46
8.0.10.0000.00717.17
8.0.00.0060.01216.92
7.4.330.0000.00515.07
7.4.320.0030.00316.58
7.4.300.0000.00616.52
7.4.290.0030.00316.65
7.4.280.0000.00916.54
7.4.270.0000.00816.48
7.4.260.0070.00016.46
7.4.250.0000.00716.42
7.4.240.0040.00416.62
7.4.230.0000.00716.66
7.4.220.0090.00916.54
7.4.210.0060.00916.64
7.4.200.0000.00816.69
7.4.190.0000.00716.75
7.4.160.0090.01216.46
7.4.150.0030.01717.40
7.4.140.0080.01017.86
7.4.130.0110.00516.58
7.4.120.0100.00916.66
7.4.110.0070.01116.76
7.4.100.0170.00316.48
7.4.90.0070.01416.61
7.4.80.0110.01119.39
7.4.70.0000.01616.64
7.4.60.0080.00816.60
7.4.50.0000.00816.67
7.4.40.0110.00816.39
7.4.30.0120.00916.41
7.4.10.0070.01215.13
7.4.00.0060.01014.98
7.3.330.0040.00413.56
7.3.320.0030.00313.29
7.3.310.0040.00416.52
7.3.300.0030.00316.36
7.3.290.0140.00816.50
7.3.280.0120.00616.48
7.3.270.0110.00717.40
7.3.260.0140.00316.48
7.3.250.0090.00916.49
7.3.240.0030.01316.43
7.3.230.0160.00616.47
7.3.210.0120.00816.56
7.3.200.0090.01019.39
7.3.190.0140.00716.52
7.3.180.0100.00716.60
7.3.170.0090.00616.46
7.3.160.0070.01016.73
7.3.130.0070.00714.59
7.3.120.0070.01014.88
7.3.110.0030.01514.96
7.3.100.0050.00814.86
7.3.90.0020.01114.88
7.3.80.0050.00914.77
7.3.70.0080.00814.73
7.3.60.0040.00714.91
7.3.50.0090.00314.80
7.3.40.0020.01214.88
7.3.30.0120.00514.95
7.3.20.0020.00816.81
7.3.10.0090.00516.69
7.3.00.0070.00816.72
7.2.330.0170.00716.86
7.2.320.0090.00916.58
7.2.310.0120.00616.64
7.2.300.0100.00716.83
7.2.290.0110.00616.89
7.2.260.0050.01314.94
7.2.250.0080.00915.14
7.2.240.0060.00915.05
7.2.230.0030.01115.18
7.2.220.0080.00915.08
7.2.210.0030.01015.15
7.2.200.0070.00515.07
7.2.190.0050.01015.02
7.2.180.0030.01015.18
7.2.170.0080.00815.10
7.2.160.0030.01115.23
7.2.150.0040.00916.88
7.2.140.0080.00716.98
7.2.130.0020.01416.80
7.2.120.0060.00916.94
7.2.110.0060.00816.87
7.2.100.0090.00516.93
7.2.90.0060.00517.00
7.2.80.0040.01316.85
7.2.70.0090.00616.91
7.2.60.0060.00816.77
7.2.50.0070.00716.86
7.2.40.0060.01016.89
7.2.30.0040.00716.84
7.2.20.0020.01416.92
7.2.10.0070.00816.94
7.2.00.0060.00717.56
7.1.330.0050.01115.76
7.1.320.0050.00915.84
7.1.310.0050.00815.70
7.1.300.0050.00815.56
7.1.290.0030.00915.75
7.1.280.0070.00515.88
7.1.270.0070.00715.56
7.1.260.0090.00615.78
7.1.250.0070.00715.80
7.1.240.0060.00915.64
7.1.230.0050.01015.86
7.1.220.0070.00615.75
7.1.210.0020.01015.73
7.1.200.0020.01215.83
7.1.190.0050.00715.63
7.1.180.0080.00515.77
7.1.170.0060.00615.57
7.1.160.0030.01115.64
7.1.150.0040.00815.86
7.1.140.0060.00715.69
7.1.130.0020.01015.53
7.1.120.0040.00815.76
7.1.110.0060.00815.63
7.1.100.0020.00916.33
7.1.90.0060.00815.65
7.1.80.0050.00615.74
7.1.70.0040.00716.27
7.1.60.0060.00916.80
7.1.50.0050.01116.09
7.1.40.0060.00815.71
7.1.30.0080.00615.80
7.1.20.0050.00715.77
7.1.10.0050.00915.77
7.1.00.0050.02517.42
7.0.330.0080.00515.45
7.0.320.0060.00715.40
7.0.310.0040.00915.39
7.0.300.0030.00815.25
7.0.290.0020.01115.24
7.0.280.0040.00815.38
7.0.270.0060.00715.43
7.0.260.0050.00815.36
7.0.250.0050.00915.33
7.0.240.0070.00615.35
7.0.230.0090.00415.38
7.0.220.0030.00815.50
7.0.210.0070.00715.37
7.0.200.0050.00715.73
7.0.190.0060.00715.39
7.0.180.0060.00715.40
7.0.170.0050.01015.44
7.0.160.0050.00815.47
7.0.150.0050.01115.55
7.0.140.0050.02417.09
7.0.130.0050.00715.40
7.0.120.0070.00715.40
7.0.110.0020.01115.43
7.0.100.0040.00915.37
7.0.90.0060.00615.54
7.0.80.0060.00715.36
7.0.70.0040.00715.43
7.0.60.0060.02416.40
7.0.50.0070.02216.08
7.0.40.0060.02614.96
7.0.30.0100.01415.03
7.0.20.0160.02215.07
7.0.10.0040.01515.11
7.0.00.0070.01615.07
5.6.400.0060.00414.54
5.6.390.0020.01314.56
5.6.380.0100.00314.45
5.6.370.0050.00814.48
5.6.360.0050.00714.52
5.6.350.0090.00514.59
5.6.340.0060.00714.64
5.6.330.0040.00814.57
5.6.320.0020.01114.55
5.6.310.0060.00514.33
5.6.300.0050.00814.52
5.6.290.0060.00514.48
5.6.280.0040.02416.04
5.6.270.0090.00514.42
5.6.260.0010.01214.59
5.6.250.0020.01314.33
5.6.240.0050.00614.37
5.6.230.0090.00414.38
5.6.220.0040.01014.41
5.6.210.0070.02116.00
5.6.200.0070.02115.38
5.6.190.0070.02516.12
5.6.180.0110.01815.93
5.6.170.0120.02315.85
5.6.160.0040.01615.90
5.6.150.0050.02315.45
5.6.140.0050.02015.51
5.6.130.0080.01915.43
5.6.120.0070.02416.06
5.6.110.0070.02716.08
5.6.100.0050.01516.07
5.6.90.0060.02816.12
5.6.80.0080.02315.80
5.6.70.0050.01014.31
5.6.60.0030.01014.42
5.6.50.0040.01014.61
5.6.40.0060.00714.29
5.6.30.0050.00714.36
5.6.20.0080.00514.49
5.6.10.0080.00514.26
5.6.00.0010.01314.46
5.5.380.0040.00813.32
5.5.370.0070.00513.25
5.5.360.0020.00913.43
5.5.350.1080.01415.24
5.5.340.0050.01814.35
5.5.330.0050.02515.01
5.5.320.0110.01515.17
5.5.310.0080.01315.09
5.5.300.0070.02314.58
5.5.290.0040.01914.52
5.5.280.0080.02015.30
5.5.270.0080.02215.23
5.5.260.0040.02215.06
5.5.250.0070.01415.16
5.5.240.0030.02615.02
5.5.230.0060.00813.31
5.5.220.0030.01013.20
5.5.210.0080.00213.34
5.5.200.0060.00713.23
5.5.190.0030.00913.25
5.5.180.0050.00713.17
5.5.170.0030.00813.33
5.5.160.0060.00713.46
5.5.150.0060.00613.13
5.5.140.0020.01013.09
5.5.130.0040.01113.23
5.5.120.0050.00613.33
5.5.110.0030.00913.35
5.5.100.0050.00613.19
5.5.90.0060.00713.34
5.5.80.0050.01013.31
5.5.70.0050.00513.25
5.5.60.0080.00413.31
5.5.50.0040.00913.23
5.5.40.0020.00813.33
5.5.30.0070.00513.14
5.5.20.0050.00613.34
5.5.10.0060.00813.10
5.5.00.0070.00613.43
5.4.450.0070.01513.23
5.4.440.0060.01613.26
5.4.430.0090.01213.31
5.4.420.0050.01413.26
5.4.410.0070.01713.23
5.4.400.0050.01513.01
5.4.390.0080.01313.12
5.4.380.0060.01513.11
5.4.370.0080.01213.24
5.4.360.0090.01413.17
5.4.350.0090.01313.10
5.4.340.0060.01513.06
5.4.330.0030.00711.15
5.4.320.0110.01913.12
5.4.310.0100.02113.05
5.4.300.0100.02213.11
5.4.290.0100.02213.08
5.4.280.0120.02313.09
5.4.270.0140.01713.13
5.4.260.0130.02013.04
5.4.250.0120.01613.03
5.4.240.0100.01813.05
5.4.230.0080.01713.05
5.4.220.0120.02013.03
5.4.210.0090.01513.08
5.4.200.0110.02313.18
5.4.190.0080.01313.00
5.4.180.0090.01913.04
5.4.170.0140.01413.13
5.4.160.0130.01313.12
5.4.150.0130.01313.10
5.4.140.0080.02412.40
5.4.130.0110.01912.35
5.4.120.0090.02112.48
5.4.110.0130.01512.52
5.4.100.0060.02412.62
5.4.90.0100.02212.41
5.4.80.0100.01912.49
5.4.70.0090.02112.41
5.4.60.0120.02212.50
5.4.50.0110.01612.60
5.4.40.0110.01212.54
5.4.30.0100.01412.52
5.4.20.0080.02512.49
5.4.10.0100.01912.49
5.4.00.0100.01912.35
5.3.290.0100.02411.85
5.3.280.0110.02111.84
5.3.270.0090.01911.85
5.3.260.0110.01811.90
5.3.250.0110.01611.89
5.3.240.0110.02011.84
5.3.230.0070.01611.93
5.3.220.0100.02111.80
5.3.210.0140.02011.82
5.3.200.0120.02111.76
5.3.190.0130.01611.83
5.3.180.0100.01611.86
5.3.170.0120.02111.85
5.3.160.0120.02011.86
5.3.150.0090.02211.88
5.3.140.0080.01911.77
5.3.130.0110.01411.83
5.3.120.0090.02511.85
5.3.110.0080.01911.88
5.3.100.0100.02111.73
5.3.90.0110.02011.71
5.3.80.0090.02211.68
5.3.70.0110.01811.67
5.3.60.0140.01811.70
5.3.50.0110.02011.65
5.3.40.0110.01411.74
5.3.30.0140.01211.61
5.3.20.0110.02111.63
5.3.10.0090.02211.49
5.3.00.0120.01011.48
5.2.170.0120.03411.84
5.2.160.0130.03111.84
5.2.150.0150.03211.84
5.2.140.0130.02011.84
5.2.130.0130.01811.84
5.2.120.0130.03311.84
5.2.110.0150.02011.84
5.2.100.0100.02011.84
5.2.90.0120.03411.84
5.2.80.0150.02411.84
5.2.70.0170.03011.84
5.2.60.0120.01811.84
5.2.50.0170.02711.84
5.2.40.0100.02711.84
5.2.30.0100.02011.84
5.2.20.0150.02611.84
5.2.10.0100.02111.84
5.2.00.0080.03311.84
5.1.60.0130.02611.84
5.1.50.0140.02311.84
5.1.40.0110.02411.84
5.1.30.0120.02211.84
5.1.20.0130.02711.84
5.1.10.0100.01611.84
5.1.00.0100.01711.84
5.0.50.0090.01511.84
5.0.40.0070.01511.84
5.0.30.0090.01511.84
5.0.20.0060.01811.84
5.0.10.0080.01511.84
5.0.00.0050.02011.84
4.4.90.0070.01211.84
4.4.80.0080.01011.84
4.4.70.0080.01911.84
4.4.60.0080.01411.84
4.4.50.0070.01311.84
4.4.40.0070.02411.84
4.4.30.0030.01711.84
4.4.20.0080.01711.84
4.4.10.0070.01911.84
4.4.00.0030.02211.84
4.3.110.0080.01711.84
4.3.100.0060.01911.84
4.3.90.0070.01611.84
4.3.80.0050.01511.84
4.3.70.0050.02011.85
4.3.60.0060.01611.85
4.3.50.0080.01611.85
4.3.40.0070.02711.85
4.3.30.0070.01311.85
4.3.20.0030.01911.85
4.3.10.0050.01811.85
4.3.00.0010.01311.85

preferences:
42.63 ms | 400 KiB | 5 Q