3v4l.org

run code in 300+ PHP versions simultaneously
<?php class HTTPGETResponse { const RECVPROGRESS_NODATA = 0; const RECVPROGRESS_HEAD = 1; const RECVPROGRESS_BODY = 2; const RECVPROGRESS_TRAIL = 3; const RECVPROGRESS_END = 4; const ERR_NOERROR = 0; const ERR_MALFORMEDRESPONSE = 1; const ERR_INVALIDCONTENTLENGTH = 2; private $buffer = ''; private $unchunk = FALSE; public $error = 0; public $recvProgress = 0; public $httpVersion; public $responseCode; public $responseMsg; public $body = ''; public $contentLength = 0; public $headers = array(); public function create() { return new $this(); } private function setErrorState($state) { $this->error = $state; $this->buffer = NULL; } private function getBufferLine() { $line = FALSE; if (FALSE !== $pos = strpos($this->buffer, "\r\n")) { $line = substr($this->buffer, 0, $pos); $this->buffer = substr($this->buffer, $pos + 2); } return $line; } private function processBufferLine($line) { if ($this->recvProgress === self::RECVPROGRESS_NODATA) { $this->processResponseLine($line); } else { $this->processHeaderLine($line); } } private function processResponseLine($line) { if (!preg_match('#^HTTP/(1\.[01]) (\d{3}) (.+)$#i', rtrim($line), $matches)) { $this->setErrorState(self::ERR_MALFORMEDRESPONSE); } else { $this->httpVersion = $matches[1]; $this->responseCode = (int) $matches[2]; $this->responseMsg = $matches[3]; $this->recvProgress = self::RECVPROGRESS_HEAD; } } private function processHeaderLine($line) { var_dump($line); if ($line === "\r\n") { if ($this->recvProgress === self::RECVPROGRESS_HEAD) { $this->unchunk = isset($this->headers['transfer-encoding']) && strtolower($this->headers['transfer-encoding']) === 'chunked'; $this->recvProgress = self::RECVPROGRESS_BODY; } } else { list($key, $val) = explode(':', $line, 2); $key = strtolower(trim($key)); $val = trim($val); if (!isset($this->headers[$key])) { $this->headers[$key] = array(); } $this->headers[$key][] = $val; } } private function processBodyData() { if ($this->unchunk) { $this->processBodyChunks(); } else { $this->body .= $this->buffer; $this->buffer = ''; } } private function processBodyChunks() { if (strlen($this->buffer)) { if (!preg_match('/^([\da-f]+)\r\n/i', $this->buffer, $matches)) { $chunkLen = hexdec($matches[1]); if ($chunkLen > 0) { $headerLen = strlen($matches[1]) + 2; if (strlen($this->buffer) >= $chunkLen + $headerLen + 2) { $this->body .= substr($this->buffer, $headerLen, $chunkLen); $this->buffer = substr($this->buffer, $chunkLen + $headerLen + 2); } } else { $this->buffer = (string) substr($this->buffer, 5); $this->recvProgress = self::RECVPROGRESS_TRAIL; } } else { $this->setErrorState(self::ERR_MALFORMEDRESPONSE); } } } public function progress($str) { if (!$this->error) { $this->buffer .= $str; while ($this->recvProgress !== self::RECVPROGRESS_BODY && FALSE !== $line = $this->getBufferLine()) { $this->processBufferLine($line); if ($this->error) { break; } } if ($this->recvProgress === self::RECVPROGRESS_BODY) { $this->processBodyData(); } } return $this->error; } public function close() { $this->recvProgress = self::RECVPROGRESS_END; $this->contentLength = strlen($this->body); if (!$this->error && isset($this->headers['content-length'])) { if ($this->contentLength !== (int) $this->headers['content-length']) { $this->setErrorState(self::ERR_INVALIDCONTENTLENGTH); } } } } $factory = new HTTPGETResponse(); $response = $factory->create(); $chunks = array("HTTP/1.1 200 OK\r\nServer: yo-mama\r\n\r\nbooooooobs"); foreach($chunks as $chunk) { $response->progress($chunk); if ($response->error) { echo "Error!\n"; break; } } print_r($response);

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.70.0160.00317.25
8.3.60.0110.01117.13
8.3.50.0130.00517.67
8.3.40.0030.01319.27
8.3.30.0060.00919.04
8.3.20.0050.00319.14
8.3.10.0040.00420.62
8.3.00.0080.00019.63
8.2.180.0070.01117.13
8.2.170.0150.00622.96
8.2.160.0120.00421.07
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0070.00026.16
8.2.120.0000.00821.25
8.2.110.0070.00321.24
8.2.100.0040.00718.22
8.2.90.0060.00319.42
8.2.80.0050.00319.34
8.2.70.0040.00418.00
8.2.60.0030.00618.05
8.2.50.0000.00818.07
8.2.40.0040.00418.33
8.2.30.0000.00718.20
8.2.20.0080.00417.91
8.2.10.0000.00817.98
8.2.00.0120.00018.13
8.1.280.0070.00725.92
8.1.270.0030.00523.99
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0060.00322.65
8.1.230.0110.00021.04
8.1.220.0000.00817.79
8.1.210.0050.00318.94
8.1.200.0130.00017.60
8.1.190.0040.00417.64
8.1.180.0050.00318.10
8.1.170.0050.00319.04
8.1.160.0040.00418.90
8.1.150.0040.00418.89
8.1.140.0000.00717.71
8.1.130.0030.00317.88
8.1.120.0000.01017.72
8.1.110.0030.00517.58
8.1.100.0000.00717.68
8.1.90.0000.00717.63
8.1.80.0040.00417.59
8.1.70.0040.00417.53
8.1.60.0040.00417.77
8.1.50.0000.00817.65
8.1.40.0000.00817.65
8.1.30.0000.00817.73
8.1.20.0040.00417.94
8.1.10.0090.00017.77
8.1.00.0040.00417.73
8.0.300.0000.00719.94
8.0.290.0030.00617.00
8.0.280.0030.00318.44
8.0.270.0040.00417.34
8.0.260.0000.00618.52
8.0.250.0030.00617.09
8.0.240.0040.00417.10
8.0.230.0080.00017.17
8.0.220.0000.00717.10
8.0.210.0040.00417.14
8.0.200.0040.00417.12
8.0.190.0060.00317.12
8.0.180.0050.00217.14
8.0.170.0050.00517.14
8.0.160.0040.00417.15
8.0.150.0090.00217.11
8.0.140.0040.00417.11
8.0.130.0030.00313.54
8.0.120.0040.00417.05
8.0.110.0040.00417.33
8.0.100.0070.00017.00
8.0.90.0080.00017.26
8.0.80.0040.01117.28
8.0.70.0030.00617.28
8.0.60.0040.00417.27
8.0.50.0050.00217.17
8.0.30.0090.01217.38
8.0.20.0130.00617.24
8.0.10.0000.00817.31
8.0.00.0090.01617.15
7.4.330.0000.00513.22
7.4.320.0000.00716.73
7.4.300.0000.00616.96
7.4.290.0050.00216.84
7.4.280.0000.00916.88
7.4.270.0000.00716.84
7.4.260.0030.00313.56
7.4.250.0030.00616.90
7.4.240.0000.00716.98
7.4.230.0000.00717.03
7.4.220.0110.01416.87
7.4.210.0070.00717.00
7.4.200.0000.00816.81
7.4.190.0040.00417.01
7.4.160.0030.01216.68
7.4.150.0160.00317.09
7.4.140.0120.00616.71
7.4.130.0060.01216.71
7.4.120.0060.01316.81
7.4.110.0070.01116.65
7.4.100.0090.00916.70
7.4.90.0160.00616.79
7.4.80.0100.01019.39
7.4.70.0080.00816.82
7.4.60.0100.01016.75
7.4.50.0030.00616.50
7.4.40.0000.01916.57
7.4.30.0080.01116.72
7.4.00.0060.01215.19
7.3.330.0000.00713.61
7.3.320.0060.00013.51
7.3.310.0000.00816.61
7.3.300.0070.00016.57
7.3.290.0120.00316.59
7.3.280.0120.00616.64
7.3.270.0120.00616.72
7.3.260.0120.00916.62
7.3.250.0130.00616.72
7.3.240.0070.01116.61
7.3.230.0140.00816.50
7.3.210.0120.00616.76
7.3.200.0120.00416.55
7.3.190.0130.00316.68
7.3.180.0060.00916.95
7.3.170.0060.00916.75
7.3.160.0130.00616.70
7.3.120.0120.00715.16
7.3.110.0100.00714.90
7.3.100.0060.01115.21
7.3.90.0100.00615.08
7.3.80.0050.00915.18
7.3.70.0050.01115.06
7.3.60.0060.00715.14
7.3.50.0070.00614.96
7.3.40.0040.00915.15
7.3.30.0070.01014.81
7.3.20.0020.01016.86
7.3.10.0040.01116.89
7.3.00.0060.00816.91
7.2.330.0110.00716.81
7.2.320.0180.00017.07
7.2.310.0120.01216.82
7.2.300.0110.01216.97
7.2.290.0130.01016.77
7.2.250.0120.00815.44
7.2.240.0130.00715.27
7.2.230.0120.00815.54
7.2.220.0030.01115.38
7.2.210.0000.01415.49
7.2.200.0090.00515.19
7.2.190.0050.00715.11
7.2.180.0070.00515.21
7.2.170.0100.00515.40
7.2.130.0060.00917.04
7.2.120.0000.01417.17
7.2.110.0070.00416.93
7.2.100.0060.01017.16
7.2.90.0120.00317.16
7.2.80.0070.01017.12
7.2.70.0060.01117.06
7.2.60.0060.00717.12
7.2.50.0110.00916.97
7.2.40.0110.00416.91
7.2.30.0100.00317.38
7.2.20.0060.01017.12
7.2.10.0070.00317.15
7.2.00.0070.00716.94
7.1.330.0030.01115.93
7.1.320.0060.00716.02
7.1.310.0120.00216.11
7.1.300.0030.01315.95
7.1.290.0000.01216.11
7.1.280.0060.00716.10
7.1.270.0080.00515.94
7.1.260.0060.00816.22
7.1.250.0040.01415.76
7.1.200.0080.00815.86
7.1.70.0080.00517.26
7.1.60.0070.01819.30
7.1.50.0100.01317.20
7.1.00.0030.06722.45
7.0.200.0030.00516.61
7.0.140.0000.07322.16
7.0.120.0070.07022.13
7.0.60.0100.06719.98
7.0.50.0100.08318.00
7.0.40.0170.07720.44
7.0.30.0400.04320.07
7.0.20.0430.06720.21
7.0.10.0070.05020.10
7.0.00.0070.06720.10
5.6.280.0030.07720.85
5.6.210.0030.05320.66
5.6.200.0130.07718.18
5.6.190.0030.04320.61
5.6.180.0230.08720.45
5.6.170.0230.04720.48
5.6.160.0100.07320.71
5.6.150.0030.04018.21
5.6.140.0130.07318.32
5.6.130.0070.08318.30
5.6.120.0130.07721.05
5.6.110.0000.04721.00
5.6.100.0030.04720.94
5.6.90.0030.05721.04
5.6.80.0030.08320.44
5.6.70.0270.03320.43
5.5.350.0270.03720.53
5.5.340.0000.08718.07
5.5.330.0030.09320.36
5.5.320.0200.07320.28
5.5.310.0430.05020.32
5.5.300.0130.08017.99
5.5.290.0100.05717.96
5.5.280.0100.08320.91
5.5.270.0100.07720.89
5.5.260.0070.08720.80
5.5.250.0030.08320.47
5.5.240.0100.04720.38
5.4.450.0470.07719.67
5.4.440.0330.04019.52
5.4.430.0370.03719.55
5.4.420.0300.04319.45
5.4.410.0300.04019.41
5.4.400.0430.03319.16
5.4.390.0400.03319.22
5.4.380.0330.03719.09
5.4.370.0370.03319.19
5.4.360.0300.04019.16
5.4.350.0370.03318.84
5.4.340.0330.03718.95
5.4.320.0330.06718.97
5.4.310.0370.03719.09
5.4.300.0370.04019.06
5.4.290.0430.05019.19
5.4.280.0300.04318.87
5.4.270.0470.06319.31
5.4.260.0470.07019.21
5.4.250.0400.06018.84
5.4.240.0430.03318.85
5.4.230.0470.06319.05
5.4.220.0600.05319.34
5.4.210.0530.03719.08
5.4.200.0570.06718.97
5.4.190.0430.05019.21
5.4.180.0500.04718.93
5.4.170.0500.05718.97
5.4.160.0470.03319.20
5.4.150.0400.04319.06
5.4.140.0670.03016.49
5.4.130.0400.04716.48
5.4.120.0500.06316.35
5.4.110.0530.02316.48
5.4.100.0530.05716.58
5.4.90.0570.03316.47
5.4.80.0570.06016.56
5.4.70.0430.03016.55
5.4.60.0500.07016.58
5.4.50.0400.05016.49
5.4.40.0500.04716.51
5.4.30.0530.06316.45
5.4.20.0430.04316.32
5.4.10.0430.04016.44
5.4.00.0430.04015.97
5.3.290.0470.02714.71
5.3.280.0530.05314.63
5.3.270.0500.07014.73
5.3.260.0530.05314.60
5.3.250.0470.07314.67
5.3.240.0500.06714.77
5.3.230.0570.04014.62
5.3.220.0530.06314.68
5.3.210.0500.05714.84
5.3.200.0430.03714.60
5.3.190.0530.05714.61
5.3.180.0400.04014.54
5.3.170.0430.03714.59
5.3.160.0530.06714.62
5.3.150.0530.03714.53
5.3.140.0370.03714.58
5.3.130.0570.05314.82
5.3.120.0400.04014.62
5.3.110.0470.07314.52
5.3.100.0400.03714.10
5.3.90.0470.05014.24
5.3.80.0500.06314.07
5.3.70.0470.03714.07
5.3.60.0430.03314.14
5.3.50.0500.06314.02
5.3.40.0430.04314.02
5.3.30.0430.04314.12
5.3.20.0600.05313.76
5.3.10.0430.04313.79
5.3.00.0470.04313.60
5.2.170.0330.03311.12
5.2.160.0430.05011.16
5.2.150.0470.06011.21
5.2.140.0300.03711.28
5.2.130.0470.03311.17
5.2.120.0430.03311.09
5.2.110.0330.06311.27
5.2.100.0430.03311.21
5.2.90.0500.04711.27
5.2.80.0500.04311.20
5.2.70.0400.03711.39
5.2.60.0400.03311.02
5.2.50.0470.04311.08
5.2.40.0330.05311.06
5.2.30.0370.05711.04
5.2.20.0370.05711.11
5.2.10.0370.05710.84
5.2.00.0300.03710.85
5.1.60.0370.0479.99
5.1.50.0400.0479.99
5.1.40.0430.04010.12
5.1.30.0400.05010.32
5.1.20.0370.04710.42
5.1.10.0270.04710.01
5.1.00.0500.02310.11
5.0.50.0270.0239.99
5.0.40.0170.0209.99
5.0.30.0200.0279.99
5.0.20.0170.0279.99
5.0.10.0230.0379.99
5.0.00.0200.0609.99
4.4.90.0170.0339.99
4.4.80.0170.0179.99
4.4.70.0230.0239.99
4.4.60.0170.0239.99
4.4.50.0230.0279.99
4.4.40.0200.0539.99
4.4.30.0230.0279.99
4.4.20.0200.0309.99
4.4.10.0130.0309.99
4.4.00.0170.0509.99
4.3.110.0230.0279.99
4.3.100.0170.0209.99
4.3.90.0170.0239.99
4.3.80.0200.0509.99
4.3.70.0130.0279.99
4.3.60.0170.0309.99
4.3.50.0170.0379.99
4.3.40.0170.0539.99
4.3.30.0100.0279.99
4.3.20.0070.0379.99
4.3.10.0070.0379.99
4.3.00.0130.0209.99

preferences:
47.53 ms | 401 KiB | 5 Q