3v4l.org

run code in 300+ PHP versions simultaneously
<?php function redirect($url = '', array $params = array()) { // スキーム省略に対応 $url = preg_replace_callback( '@^/{2}(?!/)@', function ($matches) { return empty($_SERVER['HTTPS']) || strcasecmp($_SERVER['HTTPS'], 'off') ? 'http://' : 'https://' ; }, $url ); // URLをパースする if (!$p = parse_url($url)) { throw new BadMethodCallException('URLのパースに失敗しました'); } // 相対URLで書かれた場合には絶対URLに補正して再パースさせる if (!isset($p['host'])) { $url = rtrim($GLOBALS['SITE_URL'], '/') . '/' . ltrim($url, '/'); if (!$p = parse_url($url) or !isset($p['host']) or !isset($p['scheme'])) { throw new BadMethodCallException('URLのパースに失敗しました'); } } // クエリ―ストリングをパースして連想配列にする parse_str(isset($p['query']) ? $p['query'] : '', $query); // URLを組み立てていく $user_and_pass[] = isset($p['user']) ? $p['user'] : null; $user_and_pass[] = isset($p['pass']) ? $p['pass'] : null; $host_and_port[] = $p['host']; $host_and_port[] = isset($p['port']) ? $p['port'] : null; $server[] = implode(':', array_filter($user_and_pass, 'is_scalar')); $server[] = implode(':', array_filter($host_and_port, 'is_scalar')); $server_and_path[] = implode('@', array_filter($server, 'strlen')); $server_and_path[] = isset($p['path']) ? ltrim($p['path'], '/') : ''; $sp_and_query[] = implode('/', $server_and_path); $sp_and_query[] = http_build_query($params + $query, '', '&'); $spq_and_fragment[] = implode('?', array_filter($sp_and_query, 'strlen')); $spq_and_fragment[] = isset($p['fragment']) ? $p['fragment'] : null; $scheme_and_spqf[] = $p['scheme']; $scheme_and_spqf[] = implode('#', array_filter($spq_and_fragment, 'is_scalar')); $url = implode('://', $scheme_and_spqf); // 改行コードやNULLバイトを削除する $url = str_replace(array("\r", "\n", "\0"), '', $url); return $url; } $SITE_URL = 'http://user:' . "\n\0\n" . 'pass@example.com:87/public'; var_dump(redirect("\n" . 'test.php?a=b'));

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.0110.01118.66
8.3.50.0120.00721.27
8.3.40.0070.00719.04
8.3.30.0140.00020.31
8.3.20.0000.00720.02
8.3.10.0050.00321.92
8.3.00.0040.00422.51
8.2.180.0070.01418.66
8.2.170.0110.00422.96
8.2.160.0120.00322.10
8.2.150.0060.00324.18
8.2.140.0050.00324.66
8.2.130.0030.00626.16
8.2.120.0040.00421.00
8.2.110.0030.00622.22
8.2.100.0120.00017.77
8.2.90.0040.00419.16
8.2.80.0000.00819.41
8.2.70.0060.00318.00
8.2.60.0040.00418.04
8.2.50.0040.00418.07
8.2.40.0000.00818.21
8.2.30.0040.00419.49
8.2.20.0000.00917.98
8.2.10.0000.00818.11
8.2.00.0030.00518.00
8.1.280.0110.00325.92
8.1.270.0030.00523.99
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0090.00023.97
8.1.230.0080.00319.01
8.1.220.0040.00417.91
8.1.210.0030.00618.77
8.1.200.0090.00017.61
8.1.190.0040.00417.76
8.1.180.0050.00318.10
8.1.170.0040.00418.74
8.1.160.0040.00419.02
8.1.150.0040.00418.88
8.1.140.0040.00417.61
8.1.130.0080.00017.79
8.1.120.0040.00417.68
8.1.110.0040.00417.68
8.1.100.0000.00917.68
8.1.90.0000.00717.68
8.1.80.0070.00017.66
8.1.70.0030.00517.66
8.1.60.0030.00617.69
8.1.50.0030.00517.74
8.1.40.0040.00417.70
8.1.30.0080.00017.77
8.1.20.0000.00817.87
8.1.10.0040.00417.73
8.1.00.0040.00417.73
8.0.300.0000.00918.77
8.0.290.0040.00417.30
8.0.280.0000.00718.55
8.0.270.0040.00417.32
8.0.260.0080.00017.12
8.0.250.0040.00417.18
8.0.240.0000.00817.29
8.0.230.0040.00417.19
8.0.220.0000.00817.10
8.0.210.0070.00017.14
8.0.200.0000.00817.27
8.0.190.0040.00417.21
8.0.180.0040.00417.19
8.0.170.0030.00617.08
8.0.160.0040.00417.19
8.0.150.0050.00217.11
8.0.140.0040.00417.13
8.0.130.0030.00313.54
8.0.120.0040.00417.15
8.0.110.0000.00717.16
8.0.100.0000.00717.27
8.0.90.0000.00816.94
8.0.80.0110.00417.19
8.0.70.0080.00016.96
8.0.60.0050.00317.12
8.0.50.0000.00717.07
8.0.30.0070.01117.31
8.0.20.0100.00817.40
8.0.10.0070.00017.38
8.0.00.0080.01416.86
7.4.330.0060.00016.83
7.4.320.0030.00316.86
7.4.300.0030.00316.75
7.4.290.0040.00416.86
7.4.280.0000.00716.89
7.4.270.0030.00316.69
7.4.260.0030.00313.64
7.4.250.0030.00516.73
7.4.240.0000.00816.76
7.4.230.0030.00316.96
7.4.220.0140.00416.82
7.4.210.0040.01216.84
7.4.200.0030.00316.55
7.4.190.0030.00317.00
7.4.160.0070.01016.85
7.4.150.0030.01417.40
7.4.140.0080.00817.86
7.4.130.0080.00816.77
7.4.120.0090.00816.74
7.4.110.0070.01016.79
7.4.100.0060.01116.75
7.4.90.0140.00316.73
7.4.80.0080.01619.39
7.4.70.0140.00416.77
7.4.60.0160.00316.78
7.4.50.0030.00616.78
7.4.40.0050.00822.77
7.4.30.0090.00916.79
7.4.00.0070.00715.05
7.3.330.0030.00213.29
7.3.320.0060.00013.56
7.3.310.0040.00416.66
7.3.300.0040.00416.53
7.3.290.0080.01216.61
7.3.280.0080.01016.58
7.3.270.0110.00617.40
7.3.260.0090.00916.55
7.3.250.0090.00916.68
7.3.240.0170.00316.61
7.3.230.0050.01316.69
7.3.210.0090.00816.70
7.3.200.0110.00619.39
7.3.190.0130.00316.77
7.3.180.0000.01716.75
7.3.170.0140.00716.63
7.3.160.0060.00916.75
7.3.120.0110.00314.77
7.3.10.0200.00716.45
7.3.00.0210.00516.46
7.2.330.0110.00716.73
7.2.320.0110.00616.91
7.2.310.0070.01017.00
7.2.300.0140.00416.86
7.2.290.0070.01017.04
7.2.130.0140.00416.72
7.2.120.0210.00716.91
7.2.110.0160.00417.17
7.2.100.0100.01016.82
7.2.90.0150.00816.57
7.2.80.0150.00416.71
7.2.70.0060.01316.55
7.2.60.0050.01116.89
7.2.50.0150.00417.02
7.2.40.0110.00417.00
7.2.30.0160.00316.89
7.2.20.0180.00016.78
7.2.10.0140.00316.91
7.2.00.0110.00818.25
7.1.250.0090.00615.55
7.1.200.0170.00315.97
7.1.100.0090.00318.56
7.1.70.0060.00617.09
7.1.60.0040.01819.17
7.1.50.0070.01717.22
7.1.00.0100.06722.38
7.0.200.0000.00817.06
7.0.140.0000.08022.08
7.0.110.0070.08320.00
7.0.100.0100.03720.11
7.0.90.0130.07719.89
7.0.80.0100.07319.98
7.0.70.0100.07019.96
7.0.60.0100.04020.29
7.0.50.0070.05320.39
7.0.40.0270.06020.08
7.0.30.0100.07719.99
7.0.20.0030.06719.93
7.0.10.0130.07720.13
7.0.00.0070.08320.15
5.6.280.0100.06721.02
5.6.260.0100.06020.77
5.6.250.0070.04020.91
5.6.240.0000.04720.71
5.6.230.0030.08020.50
5.6.220.0070.08320.47
5.6.210.0070.04020.61
5.6.200.0000.05320.61
5.6.190.0170.05720.58
5.6.180.0070.07320.59
5.6.170.0170.04020.49
5.6.160.0070.03320.71
5.6.150.0100.07320.88
5.6.140.0100.05020.55
5.6.130.0070.07720.49
5.6.120.0070.04020.68
5.6.110.0070.03720.65
5.6.100.0000.04320.71
5.6.90.0130.07320.56
5.6.80.0030.07319.92
5.6.70.0030.07320.02
5.6.60.0030.08019.96
5.6.50.0030.07719.96
5.6.40.0100.03019.85
5.6.30.0100.06019.85
5.6.20.0070.06720.24
5.6.10.0200.06320.03
5.6.00.0070.05720.06
5.5.380.0030.04017.61
5.5.370.0000.04317.56
5.5.360.0130.07317.51
5.5.350.0030.06017.57
5.5.340.0170.06717.89
5.5.330.0030.05018.23
5.5.320.0130.06718.11
5.5.310.0070.07017.93
5.5.300.0070.03317.93
5.5.290.0070.03718.09
5.5.280.0100.07018.10
5.5.270.0000.08018.09
5.5.260.0070.04318.11
5.5.250.0100.05717.86
5.5.240.0070.03317.52
5.5.230.0000.06317.46
5.5.220.0130.05717.29
5.5.210.0070.05017.51
5.5.200.0000.08017.27
5.5.190.0070.07317.29
5.5.180.0100.03017.58
5.5.160.0200.06017.49
5.5.150.0070.07717.45
5.5.140.0030.05017.60
5.5.130.0130.05317.32
5.5.120.0030.06017.40
5.5.110.0100.03017.48
5.5.100.0100.05317.41
5.5.90.0030.07317.48
5.5.80.0100.07317.18
5.5.70.0070.07017.15
5.5.60.0070.07017.29
5.5.50.0030.04717.37
5.5.40.0070.05717.46
5.5.30.0000.04317.15
5.5.20.0070.08017.16
5.5.10.0100.06017.46
5.5.00.0030.06017.17
5.4.450.0100.05719.28
5.4.440.0030.05719.47
5.4.430.0130.07319.41
5.4.420.0030.07019.48
5.4.410.0130.03019.21
5.4.400.0100.06019.23
5.4.390.0030.04719.02
5.4.380.0070.06719.02
5.4.370.0030.03319.20
5.4.360.0100.07019.02
5.4.350.0100.03019.04
5.4.340.0030.06719.04
5.4.320.0100.07318.95
5.4.310.0030.03319.00
5.4.300.0030.07019.09
5.4.290.0030.04319.16
5.4.280.0070.04719.24
5.4.270.0000.03719.01
5.4.260.0100.06718.99
5.4.250.0000.04319.10
5.4.240.0030.03719.33
5.4.230.0070.07719.16
5.4.220.0070.06319.33
5.4.210.0000.06719.21
5.4.200.0030.04319.33
5.4.190.0000.04318.96
5.4.180.0070.06318.99
5.4.170.0070.04018.99
5.4.160.0000.04018.99
5.4.150.0070.04719.16
5.4.140.0030.07316.64
5.4.130.0030.06016.60
5.4.120.0130.06016.64
5.4.110.0100.07016.63
5.4.100.0100.06316.59
5.4.90.0070.04316.31
5.4.80.0000.04316.71
5.4.70.0100.02716.61
5.4.60.0070.06716.45
5.4.50.0070.05316.63
5.4.40.0000.04716.39
5.4.30.0030.04316.39
5.4.20.0070.03316.29
5.4.10.0130.02716.45
5.4.00.0030.04015.95
5.3.290.0030.08314.71
5.3.280.0000.03714.76
5.3.270.0070.06314.72
5.3.260.0100.07014.49
5.3.250.0030.03314.76
5.3.240.0030.07714.67
5.3.230.0070.07314.49
5.3.220.0130.05314.67
5.3.210.0130.04314.62
5.3.200.0030.05314.73
5.3.190.0070.05714.55
5.3.180.0000.04014.59
5.3.170.0030.04014.60
5.3.160.0000.05314.57
5.3.150.0070.05714.74
5.3.140.0030.06314.61
5.3.130.0070.04014.66
5.3.120.0070.04314.57
5.3.110.0070.03314.72
5.3.100.0030.04314.21
5.3.90.0070.06314.14
5.3.80.0070.03314.07
5.3.70.0000.03713.91
5.3.60.0030.04714.02
5.3.50.0000.04013.84
5.3.40.0030.03313.99
5.3.30.0100.02713.97
5.3.20.0070.03313.86
5.3.10.0100.02713.64
5.3.00.0030.03713.66
5.2.170.0000.03011.94
5.2.160.0030.02711.94
5.2.150.0000.03011.94
5.2.140.0070.02311.94
5.2.130.0030.03711.94
5.2.120.0030.02711.94
5.2.110.0000.04011.94
5.2.100.0100.05711.94
5.2.90.0000.03011.94
5.2.80.0030.03011.94
5.2.70.0070.02711.94
5.2.60.0030.03011.94
5.2.50.0070.02311.94
5.2.40.0030.04311.94
5.2.30.0070.05711.94
5.2.20.0030.02311.94
5.2.10.0000.04011.94
5.2.00.0000.03011.94
5.1.60.0070.02311.94
5.1.50.0000.02711.94
5.1.40.0000.02711.94
5.1.30.0030.03711.94
5.1.20.0030.02311.94
5.1.10.0030.05711.94
5.1.00.0030.02711.94
5.0.50.0030.01711.94
5.0.40.0030.02311.94
5.0.30.0000.04311.94
5.0.20.0070.04011.94
5.0.10.0000.04311.94
5.0.00.0000.02711.94
4.4.90.0000.01311.94
4.4.80.0030.01711.94
4.4.70.0030.02311.94
4.4.60.0000.01711.94
4.4.50.0030.01311.94
4.4.40.0000.02311.94
4.4.30.0000.02011.94
4.4.20.0000.03011.94
4.4.10.0000.03311.94
4.4.00.0070.02011.94
4.3.110.0070.02711.94
4.3.100.0000.03011.94
4.3.90.0000.01711.94
4.3.80.0000.05711.94
4.3.70.0000.01711.94
4.3.60.0030.04311.94
4.3.50.0000.01311.94
4.3.40.0000.04311.94
4.3.30.0000.01711.94
4.3.20.0000.01711.94
4.3.10.0000.03011.94
4.3.00.0000.02011.94

preferences:
39.44 ms | 401 KiB | 5 Q