3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Autoloading based on the PSR-0 standard and extended predefined configuration * https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md */ spl_autoload_register(function ($class) { // Use predefined paths $paths = explode(PATH_SEPARATOR, get_include_path()); // fix for UNIX if (PATH_SEPARATOR === ':') { foreach ($paths as $key => $value) { if (substr(strtolower($value), 0, 4) === 'http' && isset($paths[$key + 1])) { $paths[$key] .= ':' . $paths[$key + 1]; unset($paths[$key + 1]); } } } // remove duplicated paths $paths = array_values(array_unique($paths)); // Realpaths and URLs array_walk($paths, function (&$path) { $path = filter_var($path, FILTER_VALIDATE_URL) ? rtrim($path, '/') . '/' : rtrim(realpath($path), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; }); array_filter($paths, function ($path) { return !is_null(trim($path, '/' . DIRECTORY_SEPARATOR)); }); // Use predefined extensions $extensions = explode(',', spl_autoload_extensions()); // Remove initial backslash `\` $class = ltrim($class, chr(92)); // Explode by `\` $tokens = explode(chr(92), $class); // Each `_` character in the CLASS NAME is converted to a `DIRECTORY_SEPARATOR`. // The `_` character has no special meaning in the namespace. $class_tokens = explode('_', end($tokens)); array_pop($tokens); array_walk($class_tokens, function (&$class_token) use (&$tokens) { $tokens[] = $class_token; }); // Check if file exists and require(_once) it foreach ($paths as $path) { foreach ($extensions as $extension) { $uri = filter_var($path, FILTER_VALIDATE_URL) ? $path . implode('/', $tokens) . $extension : $path . implode(DIRECTORY_SEPARATOR, $tokens) . $extension; if (filter_var($uri, FILTER_VALIDATE_URL)) { if (ini_get('allow_url_fopen') && ini_get('allow_url_include')) { // http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-include // spl_autoload_register returns bool // http://it2.php.net/manual/en/function.spl-autoload-register.php return ((require_once $uri) === 1); } elseif (extension_loaded('curl')) { // cURL is a preferred mode $ch = curl_init($uri); curl_setopt_array($ch, array( CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_BINARYTRANSFER => 1, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_FRESH_CONNECT => 1, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_FAILONERROR => 1 )); $content = curl_exec($ch); // Loading only right pages if (curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200) { continue; } curl_close($ch); // if the time it's not a problem the file will be saved for a faster access // file will be written in first accessible directory in `$paths` if (!ini_get('max_execution_time')) { foreach ($paths as $path) { if (filter_var($path, FILTER_VALIDATE_URL)) { continue; } $file = $path . implode(DIRECTORY_SEPARATOR, $tokens) . $extension; if (is_writable($path) && (!file_exists($file) || is_writable($file))) { // create the directory if (!file_exists(dirname($file))) { for ($i = 0; $i < count($tokens); $i++) { $dir = $path . implode(DIRECTORY_SEPARATOR, array_slice($tokens, 0, $i)); if (!file_exists($dir)) { mkdir($dir); } } } $handle = fopen($file, 'w+'); fwrite($handle, $content); fclose($handle); return ((require_once $file) === 1); } } } elseif (is_writable(sys_get_temp_dir())) { $tmp_file = tempnam(sys_get_temp_dir(), '__autoload'); $handle = fopen($tmp_file, 'w+'); fwrite($handle, $content); fclose($handle); $return = ((require_once $tmp_file) === 1); unlink($tmp_file); // spl_autoload_register returns bool // http://it2.php.net/manual/en/function.spl-autoload-register.php return $return; } } } elseif (file_exists($uri)) { // spl_autoload_register returns bool // http://it2.php.net/manual/en/function.spl-autoload-register.php return ((require_once $uri) === 1); } } } // spl_autoload_register returns bool // http://it2.php.net/manual/en/function.spl-autoload-register.php return false; }); /** * A PHP (5.3+) microframework based on anonymous functions. */ $mf = function () { /** * Used to store functions and allow recursive callbacks. * @var null|callable */ static $deploy = null; /** * Defined matches. * @var array */ static $ms = array(); /** * Dependency Injection callbacks, used for settings too. * @var null|array */ static $di = null; // there's already a container for variables if (is_null($di)) { $di =& $GLOBALS; } /** * This variable is a constant during an instance. * @var null|string */ static $base = null; // base path for each route defined once if (is_null($base)) { $base = quotemeta(rtrim(dirname($_SERVER['SCRIPT_NAME']), '/')); } // used to shorten code $num_args = func_num_args(); $get_args = func_get_args(); // used to retrieve currently defined matches // http://www.php.net/manual/en/regexp.reference.conditional.php // http://stackoverflow.com/questions/14598972/catch-all-regular-expression switch ($num_args) { case 0: { if (PHP_SAPI !== 'cli') { return '/?(?!(' . implode('|', $ms) . ')$).*'; } break; } case 1: { if (is_scalar($get_args[0])) { // using $GLOBALS as a container, variable names must match // this regular expression // http://www.php.net/manual/en/language.variables.basics.php if (preg_match('#^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*#', $get_args[0])) { return is_callable($di[$get_args[0]]) ? call_user_func($di[$get_args[0]]) : $di[$get_args[0]]; } } break; } case 2: { if (is_scalar($get_args[0])) { // using $GLOBALS as a container, variable names must match // this regular expression // http://www.php.net/manual/en/language.variables.basics.php if (preg_match('#^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*#', $get_args[0])) { // functions used for Dependency Injection and settings return $di[$get_args[0]] = $get_args[1]; } } break; } } // functions have to be stored only once if (is_null($deploy) && PHP_SAPI === 'cli') { /** * Command line interface for the main function. * * @link http://php.net/manual/en/language.types.float.php * * @param callback $cb Function invoked when script ends * @param integer $priority Set `$cb` priority from 0 (high) to ~1.8e308 (low) * @return void */ $deploy = function ($cb, $priority = 0) use (&$deploy) { // Checking well formed call assert(is_callable($cb)); assert(is_numeric($priority)); /** * Arguments passed to the script. * @link http://php.net/manual/en/reserved.variables.argv.php * @var array */ $argv = $GLOBALS['argv']; if ($priority > 0) { // Recursion is used to set callback priority register_shutdown_function($deploy, $cb, $priority - 1); } else { $argv[0] = $cb; // register_shutdown_function is used to call added functions when script ends // http://it2.php.net/manual/en/function.register-shutdown-function.php call_user_func_array('register_shutdown_function', $argv); } }; } elseif (is_null($deploy)) { /** * Function used as a router. * * @link http://php.net/manual/en/language.types.float.php * * @param string $regex Regular expression used to match requested URL * @param callback $cb Function invoked when there's a match * @param string $method Request method(s) * @param float $priority Set `$cb` priority from 0 (high) to ~1.8e308 (low) * @return void */ $deploy = function ($regex, $cb, $method = 'GET', $priority = 0) use (&$deploy, $ms, $base) { // Checking well formed call assert(is_string($regex)); assert(is_callable($cb)); assert(is_string($method)); assert(is_numeric($priority)); // match stored as unique using the Adler-32 algorithm that is faster than md5 // http://en.wikipedia.org/wiki/Adler-32 // http://3v4l.org/7MC3j $ms[hash('adler32', $regex)] = $regex; if ($priority > 0) { // Recursion is used to set callback priority register_shutdown_function($deploy, $regex, $cb, $method, $priority - 1); } elseif (preg_match('#' . $method . '#', $_SERVER['REQUEST_METHOD'])) { if (preg_match('#^' . $base . $regex . '$#', $_SERVER['REQUEST_URI'], $matches)) { // Named subpatterns are allowed // http://it2.php.net/manual/en/regexp.reference.subpatterns.php $matches = array_unique($matches); // If matches is provided, then it is filled with the results of search. // $matches[0] will contain the text that matched the full pattern, // $matches[1] will have the text that matched the first captured parenthesized // subpattern, and so on. $start_match = $matches[0]; unset($matches[0]); // Snippet used to extract parameter from a callable object. $Reflector = (is_string($cb) && function_exists($cb)) || $cb instanceof Closure ? new ReflectionFunction($cb) : new ReflectionMethod($cb); $params = array(); foreach ($Reflector->getParameters() as $parameter) { // reset to prevent key value $params[$parameter->name] = null; } // user can use named parameters only if explicitly requested if (array_intersect(array_keys($params), array_keys($matches))) { $matches = array_merge($params, $matches); } array_unshift($matches, $cb); // register_shutdown_function is used to call added functions when script ends // http://it2.php.net/manual/en/function.register-shutdown-function.php call_user_func_array('register_shutdown_function', $matches); } } }; } return call_user_func_array($deploy, func_get_args()); }; $mf(function(){ echo "Hello World"; });

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.60.0070.00716.63
8.3.50.0080.00821.88
8.3.40.0150.00018.97
8.3.30.0070.00719.27
8.3.20.0080.00020.46
8.3.10.0040.00421.98
8.3.00.0000.00817.91
8.2.180.0150.00716.75
8.2.170.0090.00622.96
8.2.160.0070.00720.60
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0080.00020.94
8.2.110.0060.00322.30
8.2.100.0110.00019.51
8.2.90.0030.00519.22
8.2.80.0040.00417.97
8.2.70.0000.00917.63
8.2.60.0060.00318.05
8.2.50.0030.00618.07
8.2.40.0080.00018.28
8.2.30.0030.00518.17
8.2.20.0000.00817.61
8.2.10.0000.00818.07
8.2.00.0060.00317.60
8.1.280.0110.00425.92
8.1.270.0090.00023.97
8.1.260.0060.00326.35
8.1.250.0080.00028.09
8.1.240.0090.00318.49
8.1.230.0080.00419.20
8.1.220.0030.00617.74
8.1.210.0030.00518.77
8.1.200.0100.00017.35
8.1.190.0030.00617.10
8.1.180.0040.00418.10
8.1.170.0000.00818.54
8.1.160.0050.00222.07
8.1.150.0000.00818.88
8.1.140.0040.00417.34
8.1.130.0040.00418.00
8.1.120.0030.00617.47
8.1.110.0030.00517.51
8.1.100.0040.00417.37
8.1.90.0000.01017.48
8.1.80.0060.00317.38
8.1.70.0000.00717.34
8.1.60.0030.00717.47
8.1.50.0050.00317.43
8.1.40.0060.00317.41
8.1.30.0040.00417.50
8.1.20.0000.00817.72
8.1.10.0050.00317.43
8.1.00.0090.00017.35
8.0.300.0040.00418.77
8.0.290.0080.00017.00
8.0.280.0000.00718.57
8.0.270.0070.00017.47
8.0.260.0000.00717.41
8.0.250.0000.00717.20
8.0.240.0040.00417.22
8.0.230.0070.00017.05
8.0.220.0030.00417.13
8.0.210.0050.00317.14
8.0.200.0080.00017.22
8.0.190.0070.00017.16
8.0.180.0060.00317.05
8.0.170.0030.00617.03
8.0.160.0000.00817.06
8.0.150.0000.00917.07
8.0.140.0000.00717.11
8.0.130.0000.00813.58
8.0.120.0030.00715.26
8.0.110.0080.00215.31
8.0.100.0080.00315.23
8.0.90.0090.00315.31
8.0.80.0080.00715.29
8.0.70.0070.00415.30
8.0.60.0040.00615.32
8.0.50.0050.00615.31
8.0.30.0120.00716.08
8.0.20.0100.00716.14
8.0.10.0010.01015.47
8.0.00.0060.00915.89
7.4.330.0000.00615.00
7.4.320.0000.00716.68
7.4.300.0000.00716.65
7.4.290.0070.00016.64
7.4.280.0060.00316.74
7.4.270.0040.00416.74
7.4.260.0030.00716.78
7.4.250.0020.00715.07
7.4.240.0050.00515.59
7.4.230.0080.00315.00
7.4.220.0110.00915.06
7.4.210.0120.00315.08
7.4.200.0060.00515.03
7.4.190.0080.00713.55
7.4.180.0030.00613.42
7.4.160.0100.00415.10
7.4.150.0050.00915.45
7.4.140.0080.00816.34
7.4.130.0090.00815.64
7.4.120.0130.00415.56
7.4.110.0030.01314.94
7.4.100.0080.00715.03
7.4.90.0080.00815.05
7.4.80.0130.00516.34
7.4.70.0110.00515.03
7.4.60.0080.00515.00
7.4.50.0050.00615.02
7.4.40.0080.00714.93
7.4.30.0070.00814.96
7.4.20.0000.01013.38
7.4.10.0060.00313.59
7.4.00.0050.01014.62
7.3.330.0060.00013.53
7.3.320.0050.00013.49
7.3.310.0030.00615.04
7.3.300.0050.00315.00
7.3.290.0050.00715.09
7.3.280.0090.00615.80
7.3.270.0090.00515.47
7.3.260.0080.00814.98
7.3.250.0080.01015.65
7.3.240.0080.00515.06
7.3.230.0050.00715.08
7.3.220.0090.00013.32
7.3.210.0090.00415.02
7.3.200.0090.00515.15
7.3.190.0090.00615.06
7.3.180.0100.00215.15
7.3.170.0040.00715.15
7.3.160.0100.00215.03
7.3.150.0040.00413.46
7.3.140.0090.00013.44
7.3.130.0060.00313.43
7.3.120.0070.00514.53
7.3.110.0060.00814.47
7.3.100.0060.00814.59
7.3.90.0050.00714.67
7.3.80.0070.00314.49
7.3.70.0040.00414.60
7.3.60.0030.00814.41
7.3.50.0030.00714.52
7.3.40.0020.00814.50
7.3.30.0030.00614.49
7.3.20.0070.00516.30
7.3.10.0030.00916.20
7.3.00.0060.00316.18
7.2.340.0120.00013.40
7.2.330.0170.00215.17
7.2.320.0120.00715.16
7.2.310.0050.01315.08
7.2.300.0040.01015.07
7.2.290.0070.01015.34
7.2.280.0080.00413.40
7.2.270.0060.00713.60
7.2.260.0090.00413.51
7.2.250.0070.01014.34
7.2.240.0050.01114.56
7.2.230.0080.00614.66
7.2.220.0060.00714.65
7.2.210.0070.00914.66
7.2.200.0060.01014.73
7.2.190.0090.00514.56
7.2.180.0070.01014.61
7.2.170.0070.00814.65
7.2.160.0060.00714.47
7.2.150.0040.00916.21
7.2.140.0080.00616.20
7.2.130.0100.00516.17
7.2.120.0040.00816.32
7.2.110.0080.00616.34
7.2.100.0060.01016.32
7.2.90.0080.00416.49
7.2.80.0080.00416.34
7.2.70.0070.00716.44
7.2.60.0090.00416.47
7.2.50.0100.00416.43
7.2.40.0090.00416.44
7.2.30.0050.00916.47
7.2.20.0070.00716.46
7.2.10.0070.00816.47
7.2.00.0090.00517.30
7.1.330.0020.01115.42
7.1.320.0050.00715.42
7.1.310.0050.00815.29
7.1.300.0090.00415.42
7.1.290.0090.00615.36
7.1.280.0090.00415.25
7.1.270.0070.00415.29
7.1.260.0090.00415.42
7.1.250.0100.00215.15
7.1.240.0070.00415.12
7.1.230.0060.00615.13
7.1.220.0080.00615.16
7.1.210.0090.00415.09
7.1.200.0070.00615.21
7.1.190.0080.00315.06
7.1.180.0090.00415.02
7.1.170.0080.00414.92
7.1.160.0040.00915.02
7.1.150.0100.00315.17
7.1.140.0060.00815.07
7.1.130.0050.00914.99
7.1.120.0080.00315.12
7.1.110.0020.00814.96
7.1.100.0080.00516.05
7.1.90.0080.00414.92
7.1.80.0110.00215.02
7.1.70.0060.00515.72
7.1.60.0050.01116.66
7.1.50.0090.00515.78
7.1.40.0080.00315.07
7.1.30.0030.00815.23
7.1.20.0070.00314.96
7.1.10.0070.00615.12
7.1.00.0070.02817.52
7.0.330.0120.00014.13
7.0.320.0060.00714.67
7.0.310.0100.00314.74
7.0.300.0080.00614.86
7.0.290.0080.00614.75
7.0.280.0050.00614.73
7.0.270.0020.01014.80
7.0.260.0070.00614.91
7.0.250.0050.00914.81
7.0.240.0050.00714.94
7.0.230.0040.00814.80
7.0.220.0080.00514.88
7.0.210.0070.00514.78
7.0.200.0050.00615.54
7.0.190.0080.00414.89
7.0.180.0070.00714.74
7.0.170.0050.00614.90
7.0.160.0090.00414.72
7.0.150.0060.00514.90
7.0.140.0070.02617.22
7.0.130.0060.00714.95
7.0.120.0040.00814.80
7.0.110.0100.00214.83
7.0.100.0170.02616.61
7.0.90.0070.02316.47
7.0.80.0100.02716.49
7.0.70.0150.03116.56
7.0.60.0100.02916.70
7.0.50.0130.02916.75
7.0.40.0060.03415.90
7.0.30.0070.02015.88
7.0.20.0050.02815.89
7.0.10.0080.03015.99
7.0.00.0060.01815.95
5.6.400.0080.00412.64
5.6.390.0080.00513.00
5.6.380.0070.00513.74
5.6.370.0080.00313.56
5.6.360.0060.00713.74
5.6.350.0040.00613.69
5.6.340.0040.01013.69
5.6.330.0060.00613.49
5.6.320.0090.00313.63
5.6.310.0100.00413.68
5.6.300.0050.00813.71
5.6.290.0040.00813.57
5.6.280.0070.02816.21
5.6.270.0070.00613.82
5.6.260.0060.00713.64
5.6.250.0130.02716.01
5.6.240.0110.02816.09
5.6.230.0090.03215.99
5.6.220.0090.03016.09
5.6.210.0070.02616.01
5.6.200.0090.02716.20
5.6.190.0060.01816.30
5.6.180.0080.02616.36
5.6.170.0090.02716.09
5.6.160.0090.02916.18
5.6.150.0100.01616.16
5.6.140.0070.01816.20
5.6.130.0090.03316.25
5.6.120.0070.02416.27
5.6.110.0060.02116.19
5.6.100.0070.02516.12
5.6.90.0060.03416.15
5.6.80.0080.01615.89
5.6.70.0080.02515.99
5.6.60.0080.02916.03
5.6.50.0050.02515.93
5.6.40.0050.01815.93
5.6.30.0110.02715.93
5.6.20.0050.02615.94
5.6.10.0060.02615.95
5.6.00.0060.02915.78
5.5.380.0100.02815.07
5.5.370.0080.02615.00
5.5.360.0050.02314.86
5.5.350.0080.02914.87
5.5.340.0040.02115.08
5.5.330.0050.03214.92
5.5.320.0060.02914.99
5.5.310.0040.02715.05
5.5.300.0080.02514.92
5.5.290.0040.01915.02
5.5.280.0100.03015.14
5.5.270.0090.02915.12
5.5.260.0080.03315.01
5.5.250.0050.02814.97
5.5.240.0100.02614.84
5.5.230.0080.01414.87
5.5.220.0050.03014.88
5.5.210.0050.02814.86
5.5.200.0060.03014.73
5.5.190.0030.02314.79
5.5.180.0090.02414.78
5.5.170.0070.00713.51
5.5.160.0070.02814.86
5.5.150.0090.02614.79
5.5.140.0050.02514.66
5.5.130.0030.02114.69
5.5.120.0050.03014.76
5.5.110.0040.03214.71
5.5.100.0040.03414.74
5.5.90.0050.02714.73
5.5.80.0090.02614.79
5.5.70.0040.01814.84
5.5.60.0030.03414.77
5.5.50.0070.02414.74
5.5.40.0080.02214.84
5.5.30.0030.01714.77
5.5.20.0050.01914.81
5.5.10.0100.02514.73
5.5.00.0100.02714.77
5.4.450.0050.03014.50
5.4.440.0060.03114.58
5.4.430.0060.02914.39
5.4.420.0060.01614.50
5.4.410.0050.02214.46
5.4.400.0050.01514.40
5.4.390.0050.02814.42
5.4.380.0050.03314.36
5.4.370.0080.02814.46
5.4.360.0060.02314.35
5.4.350.0060.02814.43
5.4.340.0130.01014.37
5.4.330.0060.00312.08
5.4.320.0070.02614.42
5.4.310.0090.02414.30
5.4.300.0050.01814.42
5.4.290.0040.03014.39
5.4.280.0070.02514.43
5.4.270.0070.02814.36
5.4.260.0050.02814.44
5.4.250.0060.01714.34
5.4.240.0040.01514.39
5.4.230.0040.02914.39
5.4.220.0050.02614.39
5.4.210.0060.01714.39
5.4.200.0080.01814.34
5.4.190.0050.02214.36
5.4.180.0070.02414.30
5.4.170.0070.02914.36
5.4.160.0080.02514.37
5.4.150.0070.02614.40
5.4.140.0060.02713.66
5.4.130.0080.01613.44
5.4.120.0050.02713.50
5.4.110.0030.02513.55
5.4.100.0070.02513.50
5.4.90.0090.01913.42
5.4.80.0030.02813.57
5.4.70.0070.02513.58
5.4.60.0060.02813.59
5.4.50.0080.01513.54
5.4.40.0040.01813.44
5.4.30.0100.02313.50
5.4.20.0040.02813.47
5.4.10.0100.02713.60
5.4.00.0110.02113.26
5.3.290.0080.01913.08
5.3.280.0040.03013.01
5.3.270.0040.02513.13
5.3.260.0080.02613.10
5.3.250.0060.02813.09
5.3.240.0050.01813.06
5.3.230.0070.02713.08
5.3.220.0010.02213.05
5.3.210.0080.02713.03
5.3.200.0070.02713.00
5.3.190.0110.01413.01
5.3.180.0110.02213.01
5.3.170.0040.02013.04
5.3.160.0090.02713.02
5.3.150.0040.03313.14
5.3.140.0030.02313.14
5.3.130.0090.02712.99
5.3.120.0060.02813.14
5.3.110.0110.02413.01
5.3.100.0050.02712.83
5.3.90.0060.02012.83
5.3.80.0100.01212.83
5.3.70.0020.02812.76
5.3.60.0060.02812.92
5.3.50.0080.01512.89
5.3.40.0090.02212.86
5.3.30.0050.02612.84
5.3.20.0070.02512.71
5.3.10.0050.02812.61
5.3.00.0050.01812.63

preferences:
45.11 ms | 401 KiB | 5 Q