3v4l.org

run code in 300+ PHP versions simultaneously
<?php // https://github.com/jakeasmith/http_build_url /** * URL constants as defined in the PHP Manual under "Constants usable with * http_build_url()". * * @see http://us2.php.net/manual/en/http.constants.php#http.constants.url */ if (!defined('HTTP_URL_REPLACE')) { define('HTTP_URL_REPLACE', 1); } if (!defined('HTTP_URL_JOIN_PATH')) { define('HTTP_URL_JOIN_PATH', 2); } if (!defined('HTTP_URL_JOIN_QUERY')) { define('HTTP_URL_JOIN_QUERY', 4); } if (!defined('HTTP_URL_STRIP_USER')) { define('HTTP_URL_STRIP_USER', 8); } if (!defined('HTTP_URL_STRIP_PASS')) { define('HTTP_URL_STRIP_PASS', 16); } if (!defined('HTTP_URL_STRIP_AUTH')) { define('HTTP_URL_STRIP_AUTH', 32); } if (!defined('HTTP_URL_STRIP_PORT')) { define('HTTP_URL_STRIP_PORT', 64); } if (!defined('HTTP_URL_STRIP_PATH')) { define('HTTP_URL_STRIP_PATH', 128); } if (!defined('HTTP_URL_STRIP_QUERY')) { define('HTTP_URL_STRIP_QUERY', 256); } if (!defined('HTTP_URL_STRIP_FRAGMENT')) { define('HTTP_URL_STRIP_FRAGMENT', 512); } if (!defined('HTTP_URL_STRIP_ALL')) { define('HTTP_URL_STRIP_ALL', 1024); } if (!function_exists('http_build_url')) { /** * Build a URL. * * The parts of the second URL will be merged into the first according to * the flags argument. * * @param mixed $url (part(s) of) an URL in form of a string or * associative array like parse_url() returns * @param mixed $parts same as the first argument * @param int $flags a bitmask of binary or'ed HTTP_URL constants; * HTTP_URL_REPLACE is the default * @param array $new_url if set, it will be filled with the parts of the * composed url like parse_url() would return * @return string */ function http_build_url($url, $parts = array(), $flags = HTTP_URL_REPLACE, &$new_url = array()) { is_array($url) || $url = parse_url($url); is_array($parts) || $parts = parse_url($parts); isset($url['query']) && is_string($url['query']) || $url['query'] = null; isset($parts['query']) && is_string($parts['query']) || $parts['query'] = null; $keys = array('user', 'pass', 'port', 'path', 'query', 'fragment'); // HTTP_URL_STRIP_ALL and HTTP_URL_STRIP_AUTH cover several other flags. if ($flags & HTTP_URL_STRIP_ALL) { $flags |= HTTP_URL_STRIP_USER | HTTP_URL_STRIP_PASS | HTTP_URL_STRIP_PORT | HTTP_URL_STRIP_PATH | HTTP_URL_STRIP_QUERY | HTTP_URL_STRIP_FRAGMENT; } elseif ($flags & HTTP_URL_STRIP_AUTH) { $flags |= HTTP_URL_STRIP_USER | HTTP_URL_STRIP_PASS; } // Schema and host are alwasy replaced foreach (array('scheme', 'host') as $part) { if (isset($parts[$part])) { $url[$part] = $parts[$part]; } } if ($flags & HTTP_URL_REPLACE) { foreach ($keys as $key) { if (isset($parts[$key])) { $url[$key] = $parts[$key]; } } } else { if (isset($parts['path']) && ($flags & HTTP_URL_JOIN_PATH)) { if (isset($url['path']) && substr($parts['path'], 0, 1) !== '/') { $url['path'] = rtrim( str_replace(basename($url['path']), '', $url['path']), '/' ) . '/' . ltrim($parts['path'], '/'); } else { $url['path'] = $parts['path']; } } if (isset($parts['query']) && ($flags & HTTP_URL_JOIN_QUERY)) { if (isset($url['query'])) { parse_str($url['query'], $url_query); parse_str($parts['query'], $parts_query); $url['query'] = http_build_query( array_replace_recursive( $url_query, $parts_query ) ); } else { $url['query'] = $parts['query']; } } } if (isset($url['path']) && substr($url['path'], 0, 1) !== '/') { $url['path'] = '/' . $url['path']; } foreach ($keys as $key) { $strip = 'HTTP_URL_STRIP_' . strtoupper($key); if ($flags & constant($strip)) { unset($url[$key]); } } $parsed_string = ''; if (isset($url['scheme'])) { $parsed_string .= $url['scheme'] . '://'; } if (isset($url['user'])) { $parsed_string .= $url['user']; if (isset($url['pass'])) { $parsed_string .= ':' . $url['pass']; } $parsed_string .= '@'; } if (isset($url['host'])) { $parsed_string .= $url['host']; } if (isset($url['port'])) { $parsed_string .= ':' . $url['port']; } if (!empty($url['path'])) { $parsed_string .= $url['path']; } else { $parsed_string .= '/'; } if (isset($url['query'])) { $parsed_string .= '?' . $url['query']; } if (isset($url['fragment'])) { $parsed_string .= '#' . $url['fragment']; } $new_url = $url; return $parsed_string; } } var_dump( http_build_url(parse_url('http://example.com/blah')) );

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.0090.00616.63
8.3.50.0110.00718.11
8.3.40.0000.01519.09
8.3.30.0100.00719.07
8.3.20.0040.00420.20
8.3.10.0040.00421.90
8.3.00.0000.00919.38
8.2.180.0070.01418.54
8.2.170.0110.00722.96
8.2.160.0150.00420.46
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0000.00819.64
8.2.110.0040.00719.43
8.2.100.0090.00317.88
8.2.90.0090.00019.55
8.2.80.0050.00317.97
8.2.70.0000.00817.73
8.2.60.0040.00418.16
8.2.50.0030.00518.07
8.2.40.0000.00820.07
8.2.30.0020.00518.11
8.2.20.0000.00817.91
8.2.10.0050.00318.34
8.2.00.0080.00017.76
8.1.280.0180.00025.92
8.1.270.0090.00018.93
8.1.260.0050.00226.35
8.1.250.0030.00528.09
8.1.240.0100.00023.98
8.1.230.0120.00317.60
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0060.00317.36
8.1.190.0040.00417.35
8.1.180.0000.00918.10
8.1.170.0040.00420.43
8.1.160.0040.00422.00
8.1.150.0050.00319.05
8.1.140.0040.00417.43
8.1.130.0040.00417.84
8.1.120.0070.00017.57
8.1.110.0000.00917.63
8.1.100.0040.00417.52
8.1.90.0030.00517.49
8.1.80.0040.00417.43
8.1.70.0070.00017.46
8.1.60.0030.00517.64
8.1.50.0030.00617.66
8.1.40.0040.00417.63
8.1.30.0000.00817.70
8.1.20.0040.00417.71
8.1.10.0050.00317.65
8.1.00.0000.00917.53
8.0.300.0000.00718.77
8.0.290.0030.00516.88
8.0.280.0040.00418.54
8.0.270.0040.00416.80
8.0.260.0030.00317.36
8.0.250.0030.00316.94
8.0.240.0030.00316.95
8.0.230.0000.00817.06
8.0.220.0030.00316.92
8.0.210.0050.00316.96
8.0.200.0070.00016.94
8.0.190.0050.00317.01
8.0.180.0000.00817.07
8.0.170.0050.00317.04
8.0.160.0000.00816.88
8.0.150.0040.00416.96
8.0.140.0040.00416.96
8.0.130.0060.00013.46
8.0.120.0030.00516.92
8.0.110.0040.00416.96
8.0.100.0040.00417.05
8.0.90.0080.00017.02
8.0.80.0090.01516.88
8.0.70.0000.01017.00
8.0.60.0050.00316.79
8.0.50.0080.00016.93
8.0.30.0080.01217.16
8.0.20.0130.01117.40
8.0.10.0070.00017.23
8.0.00.0070.01017.02
7.4.330.0000.00515.03
7.4.320.0060.00016.56
7.4.300.0070.00016.50
7.4.290.0050.00216.71
7.4.280.0080.00016.59
7.4.270.0000.00716.61
7.4.260.0000.00716.70
7.4.250.0040.00416.49
7.4.240.0040.00416.70
7.4.230.0000.00716.64
7.4.220.0060.01216.57
7.4.210.0100.00916.75
7.4.200.0000.00816.50
7.4.160.0100.00716.51
7.4.150.0130.00517.40
7.4.140.0050.01517.86
7.4.130.0110.00616.59
7.4.120.0130.00516.53
7.4.110.0090.01316.57
7.4.100.0060.01216.68
7.4.90.0070.01016.41
7.4.80.0070.01419.39
7.4.70.0070.01116.59
7.4.60.0120.01216.46
7.4.50.0000.00916.46
7.4.40.0060.01616.61
7.4.30.0120.00916.57
7.4.00.0080.00915.04
7.3.330.0030.00313.25
7.3.320.0000.01513.31
7.3.310.0030.00316.37
7.3.300.0000.00716.30
7.3.290.0070.00916.44
7.3.280.0100.01016.47
7.3.270.0140.00617.40
7.3.260.0150.00916.81
7.3.250.0070.01316.48
7.3.240.0180.00316.52
7.3.230.0100.01316.74
7.3.210.0170.00016.70
7.3.200.0130.01019.39
7.3.190.0040.01716.71
7.3.180.0030.01316.81
7.3.170.0200.00316.41
7.3.160.0060.01516.55
7.3.120.0070.01014.68
7.3.110.0070.01114.76
7.3.100.0030.01314.76
7.3.90.0000.01014.87
7.3.80.0040.00814.86
7.3.70.0000.01115.13
7.3.60.0110.00315.09
7.3.50.0110.00315.08
7.3.40.0030.01014.89
7.3.30.0060.00815.03
7.3.20.0070.00716.80
7.3.10.0030.01016.71
7.3.00.0060.00616.63
7.2.330.0110.01116.69
7.2.320.0110.00716.99
7.2.310.0030.01316.80
7.2.300.0100.00716.81
7.2.290.0030.01516.65
7.2.250.0000.01415.35
7.2.240.0100.01015.18
7.2.230.0060.00915.15
7.2.220.0030.01014.96
7.2.210.0030.01215.26
7.2.200.0030.00915.13
7.2.190.0100.00314.98
7.2.180.0000.00915.20
7.2.170.0060.00915.07
7.2.130.0000.01517.09
7.2.120.0030.00917.07
7.2.110.0060.00917.02
7.2.100.0060.00817.00
7.2.90.0030.01017.09
7.2.80.0050.00916.88
7.2.70.0030.01016.85
7.2.60.0090.00617.01
7.2.50.0020.01317.03
7.2.40.0070.00917.10
7.2.30.0030.01117.04
7.2.20.0030.01217.14
7.2.10.0080.00717.05
7.2.00.0040.00917.69
7.1.330.0070.00715.79
7.1.320.0090.00315.73
7.1.310.0070.00715.73
7.1.300.0060.00315.77
7.1.290.0100.00615.87
7.1.280.0130.00015.84
7.1.270.0070.00715.74
7.1.260.0080.00415.97
7.1.250.0050.00915.93
7.1.240.0090.00615.77
7.1.230.0100.00315.77
7.1.220.0070.00415.58
7.1.210.0040.01115.72
7.1.200.0050.01015.77
7.1.190.0060.00915.88
7.1.180.0120.00315.73
7.1.170.0040.00815.81
7.1.160.0000.01515.77
7.1.150.0070.01015.79
7.1.140.0060.00616.00
7.1.130.0120.00315.51
7.1.120.0070.01115.74
7.1.110.0040.01115.89
7.1.100.0020.01417.03
7.1.90.0030.01015.87
7.1.80.0070.00715.89
7.1.70.0040.00616.52
7.1.60.0050.01417.65
7.1.50.0080.01016.44
7.1.40.0070.00716.08
7.1.30.0030.01015.85
7.1.20.0090.00315.91
7.1.10.0000.01315.68
7.1.00.0070.04019.09
7.0.330.0000.01515.49
7.0.320.0100.00315.44
7.0.310.0070.00415.42
7.0.300.0030.01015.39
7.0.290.0090.00015.43
7.0.280.0060.00315.44
7.0.270.0030.00915.26
7.0.260.0070.01015.54
7.0.250.0100.00315.38
7.0.240.0070.00415.26
7.0.230.0030.00615.44
7.0.220.0070.00715.55
7.0.210.0080.00315.59
7.0.200.0050.00316.19
7.0.190.0090.00015.44
7.0.180.0000.00815.34
7.0.170.0030.01115.38
7.0.160.0060.00615.48
7.0.150.0030.01015.59
7.0.140.0030.04318.80
7.0.130.0090.00415.54
7.0.120.0090.00315.35
7.0.110.0030.01315.39
7.0.100.0120.03817.57
7.0.90.0050.03317.81
7.0.80.0180.03717.75
7.0.70.0170.04317.80
7.0.60.0050.04217.62
7.0.50.0070.04517.98
7.0.40.0030.02916.85
7.0.30.0070.04416.78
7.0.20.0080.04016.76
7.0.10.0050.03516.73
7.0.00.0070.02616.79
5.6.380.0000.01414.55
5.6.370.0090.00614.69
5.6.360.0070.00714.42
5.6.350.0030.00614.65
5.6.340.0000.01414.73
5.6.330.0030.01014.67
5.6.320.0000.01414.22
5.6.310.0130.00014.53
5.6.300.0000.01014.71
5.6.290.0070.01014.78
5.6.280.0030.04117.81
5.6.270.0070.00414.79
5.6.260.0110.00414.42
5.6.250.0060.03117.64
5.6.240.0070.04717.59
5.6.230.0050.02717.68
5.6.220.0070.04317.70
5.6.210.0030.03017.64
5.6.200.0120.03817.84
5.6.190.0050.05017.86
5.6.180.0090.02817.79
5.6.170.0070.03017.86
5.6.160.0110.04117.68
5.6.150.0060.03517.74
5.6.140.0090.02817.70
5.6.130.0060.03617.73
5.6.120.0100.04017.69
5.6.110.0030.04617.74
5.6.100.0080.04817.75
5.6.90.0110.04317.85
5.6.80.0080.04717.60
5.6.70.0100.03817.40
5.6.60.0070.03017.39
5.6.50.0040.04617.66
5.6.40.0110.03617.56
5.6.30.0050.03417.30
5.6.20.0100.03517.45
5.6.10.0070.04217.46
5.6.00.0030.04717.37
5.5.380.0040.02615.96
5.5.370.0070.02215.85
5.5.360.0050.04315.93
5.5.350.0050.04715.86
5.5.340.0030.04216.21
5.5.330.0050.03316.04
5.5.320.0050.04216.09
5.5.310.0120.03516.05
5.5.300.0000.04216.16
5.5.290.0100.04016.23
5.5.280.0080.02816.05
5.5.270.0100.04016.23
5.5.260.0060.05315.92
5.5.250.0050.03715.93
5.5.240.0060.04015.70
5.5.230.0100.04215.71
5.5.220.0030.03015.70
5.5.210.0070.02515.77
5.5.200.0080.04015.70
5.5.190.0040.04315.77
5.5.180.0100.03415.78
5.5.170.0110.00011.37
5.5.160.0070.04215.69
5.5.150.0050.04115.71
5.5.140.0050.04415.88
5.5.130.0070.04215.72
5.5.120.0050.04015.68
5.5.110.0080.03615.64
5.5.100.0120.02015.75
5.5.90.0050.02615.64
5.5.80.0000.04515.66
5.5.70.0070.03515.75
5.5.60.0050.04115.82
5.5.50.0080.03715.65
5.5.40.0050.03215.74
5.5.30.0060.03615.81
5.5.20.0050.04315.74
5.5.10.0020.03515.69
5.5.00.0080.04215.63
5.4.450.0050.04315.31
5.4.440.0130.03015.23
5.4.430.0050.04315.34
5.4.420.0130.02015.24
5.4.410.0070.02515.34
5.4.400.0020.03415.18
5.4.390.0050.04115.11
5.4.380.0050.03915.06
5.4.370.0080.02215.21
5.4.360.0050.04015.15
5.4.350.0060.03615.19
5.4.340.0100.02015.01
5.4.330.0080.00011.18
5.4.320.0080.03315.29
5.4.310.0020.04615.12
5.4.300.0020.03715.10
5.4.290.0080.04015.16
5.4.280.0050.04215.11
5.4.270.0070.03715.19
5.4.260.0050.04315.11
5.4.250.0060.03015.18
5.4.240.0060.03815.22
5.4.230.0060.04115.17
5.4.220.0030.03815.11
5.4.210.0050.04015.25
5.4.200.0020.03015.05
5.4.190.0020.04415.19
5.4.180.0130.03515.32
5.4.170.0040.03915.16
5.4.160.0130.03315.09
5.4.150.0080.04115.13
5.4.140.0080.03613.87
5.4.130.0030.04313.92
5.4.120.0080.02813.98
5.4.110.0120.03213.85
5.4.100.0050.03813.99
5.4.90.0110.03113.81
5.4.80.0030.03813.87
5.4.70.0030.04313.86
5.4.60.0020.03413.76
5.4.50.0120.02913.78
5.4.40.0050.03613.89
5.4.30.0030.02513.72
5.4.20.0030.04013.83
5.4.10.0080.04013.81
5.4.00.0100.03313.64

preferences:
51.16 ms | 400 KiB | 5 Q