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) { 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.40.0080.00819.21
8.3.30.0060.00919.44
8.3.20.0060.00320.21
8.3.10.0060.00323.53
8.3.00.0100.00019.63
8.2.170.0160.00022.96
8.2.160.0040.01120.53
8.2.150.0060.00324.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0060.00322.38
8.2.110.0060.00320.44
8.2.100.0060.00620.02
8.2.90.0040.00419.20
8.2.80.0000.00817.97
8.2.70.0030.00718.00
8.2.60.0050.00519.91
8.2.50.0070.00418.07
8.2.40.0040.00420.01
8.2.30.0050.00319.93
8.2.20.0040.00418.07
8.2.10.0050.00318.25
8.2.00.0100.00017.91
8.1.270.0050.00323.67
8.1.260.0060.00326.35
8.1.250.0080.00028.09
8.1.240.0110.00723.84
8.1.230.0040.00817.89
8.1.220.0060.00317.91
8.1.210.0040.00418.77
8.1.200.0030.00617.60
8.1.190.0030.00717.59
8.1.180.0060.00318.10
8.1.170.0040.00418.61
8.1.160.0050.00322.08
8.1.150.0040.00418.81
8.1.140.0060.00317.71
8.1.130.0040.00417.87
8.1.120.0030.00517.65
8.1.110.0000.00917.72
8.1.100.0000.00817.52
8.1.90.0040.00417.66
8.1.80.0060.00317.73
8.1.70.0000.00717.59
8.1.60.0050.00317.71
8.1.50.0000.00817.68
8.1.40.0060.00317.78
8.1.30.0050.00517.80
8.1.20.0040.00417.81
8.1.10.0050.00317.69
8.1.00.0040.00417.67
8.0.300.0080.00018.77
8.0.290.0000.00817.00
8.0.280.0040.00418.51
8.0.270.0040.00417.44
8.0.260.0030.00317.29
8.0.250.0000.00717.22
8.0.240.0060.00317.11
8.0.230.0080.00017.10
8.0.220.0000.00817.20
8.0.210.0030.00517.04
8.0.200.0030.00317.23
8.0.190.0030.00617.29
8.0.180.0030.00517.16
8.0.170.0040.00417.07
8.0.160.0000.00717.10
8.0.150.0040.00417.12
8.0.140.0030.00617.00
8.0.130.0070.00013.62
8.0.120.0030.00617.05
8.0.110.0040.00417.28
8.0.100.0040.00417.20
8.0.90.0040.00417.12
8.0.80.0100.01017.16
8.0.70.0040.00417.26
8.0.60.0000.00917.16
8.0.50.0050.00317.27
8.0.30.0030.01717.42
8.0.20.0110.00817.40
8.0.10.0030.00617.21
8.0.00.0120.00717.06
7.4.330.0050.00015.13
7.4.320.0030.00516.83
7.4.300.0030.00316.78
7.4.290.0020.00516.80
7.4.280.0000.00916.80
7.4.270.0000.00716.95
7.4.260.0030.00316.88
7.4.250.0040.00416.89
7.4.240.0060.00216.95
7.4.230.0000.00816.93
7.4.220.0120.00616.96
7.4.210.0080.00716.88
7.4.200.0070.00016.97
7.4.190.0050.00216.71
7.4.160.0180.00616.77
7.4.150.0090.00917.40
7.4.140.0110.00717.86
7.4.130.0120.00716.79
7.4.120.0130.00916.83
7.4.110.0120.00916.78
7.4.100.0090.00716.82
7.4.90.0060.01216.76
7.4.80.0110.01319.39
7.4.70.0070.01116.82
7.4.60.0160.00316.93
7.4.50.0060.00316.46
7.4.40.0100.00716.80
7.4.30.0140.01116.82
7.4.00.0060.00915.20
7.3.330.0030.00313.61
7.3.320.0060.00013.56
7.3.310.0000.00816.61
7.3.300.0000.00716.52
7.3.290.0090.00916.64
7.3.280.0090.01016.57
7.3.270.0120.00617.40
7.3.260.0110.00816.62
7.3.250.0130.00516.58
7.3.240.0110.00516.66
7.3.230.0120.01216.59
7.3.210.0090.00916.80
7.3.200.0070.01019.39
7.3.190.0130.01216.86
7.3.180.0040.01216.76
7.3.170.0160.00616.76
7.3.160.0090.00616.53
7.3.120.0030.00514.96
7.2.330.0110.00616.88
7.2.320.0110.00717.01
7.2.310.0030.01516.93
7.2.300.0150.00417.00
7.2.290.0150.00316.95
7.1.100.0060.00618.22
7.1.70.0130.00317.09
7.1.60.0090.01519.46
7.1.50.0100.01617.06
7.1.00.0130.06322.45
7.0.200.0000.00816.91
7.0.140.0030.07322.17
7.0.60.0030.06720.02
7.0.50.0030.07017.98
7.0.40.0100.04320.13
7.0.30.0400.04320.10
7.0.20.0330.07020.14
7.0.10.0130.07320.10
7.0.00.0030.08020.31
5.6.280.0070.07320.86
5.6.210.0100.08320.73
5.6.200.0100.06318.23
5.6.190.0030.05720.41
5.6.180.0100.04020.77
5.6.170.0300.05020.54
5.6.160.0070.04320.47
5.6.150.0070.08018.25
5.6.140.0000.06718.22
5.6.130.0070.08318.28
5.6.120.0000.09321.00
5.6.110.0070.05720.92
5.6.100.0170.07321.08
5.6.90.0130.08021.16
5.6.80.0100.07320.41
5.5.350.0130.06720.43
5.5.340.0100.07717.96
5.5.330.0070.08720.27
5.5.320.0300.04720.19
5.5.310.0330.07320.27
5.5.300.0070.03718.04
5.5.290.0000.05017.95
5.5.280.0030.08020.71
5.5.270.0070.04320.76
5.5.260.0030.04020.82
5.5.250.0030.06320.65
5.5.240.0070.07720.41
5.4.450.0230.05719.31
5.4.440.0400.05319.18
5.4.430.0230.05019.17
5.4.420.0330.07319.27
5.4.410.0300.07719.28
5.4.400.0330.07319.13
5.4.390.0300.03719.22
5.4.380.0270.05019.22
5.4.370.0400.04019.23
5.4.360.0230.04719.14
5.4.350.0370.07019.09
5.4.340.0400.06319.20
5.4.320.0330.07019.16
5.4.310.0270.05318.95
5.4.300.0200.04018.87
5.4.290.0300.06319.06
5.4.280.0370.05018.95
5.4.270.0270.05719.16
5.4.260.0270.07019.24
5.4.250.0270.04019.15
5.4.240.0230.04319.30
5.4.230.0230.03719.06
5.4.220.0200.04718.80
5.4.210.0130.04319.19
5.4.200.0270.03018.84
5.4.190.0200.04319.12
5.4.180.0270.03019.21
5.4.170.0200.04019.21
5.4.160.0230.03319.17
5.4.150.0170.04319.14
5.4.140.0200.04016.39
5.4.130.0130.04016.54
5.4.120.0100.04316.51
5.4.110.0230.03716.41
5.4.100.0100.05316.57
5.4.90.0200.03716.41
5.4.80.0100.04316.63
5.4.70.0200.03316.57
5.4.60.0170.04016.54
5.4.50.0170.03716.45
5.4.40.0270.03716.49
5.4.30.0130.04016.35
5.4.20.0330.03316.18
5.4.10.0130.04016.57
5.4.00.0200.03315.88
5.3.290.0370.06014.73
5.3.280.0200.03714.54
5.3.270.0170.04014.77
5.3.260.0230.04314.63
5.3.250.0170.05014.76
5.3.240.0170.04014.82
5.3.230.0170.04014.63
5.3.220.0130.04314.63
5.3.210.0200.03714.67
5.3.200.0230.03714.69
5.3.190.0130.04314.70
5.3.180.0200.03714.63
5.3.170.0200.03714.60
5.3.160.0100.04314.70
5.3.150.0200.04714.60
5.3.140.0200.03714.58
5.3.130.0200.03714.62
5.3.120.0170.03714.57
5.3.110.0200.04014.57
5.3.100.0270.02714.08
5.3.90.0270.02714.07
5.3.80.0200.03314.29
5.3.70.0200.03714.29
5.3.60.0270.06713.96
5.3.50.0300.06014.00
5.3.40.0270.05314.08
5.3.30.0330.05313.88
5.3.20.0230.07313.75
5.3.10.0270.03713.63
5.3.00.0300.04013.64
5.2.170.0270.06312.86
5.2.160.0230.04312.86
5.2.150.0270.05712.86
5.2.140.0270.06012.86
5.2.130.0270.05712.86
5.2.120.0230.04312.86
5.2.110.0200.03312.86
5.2.100.0230.06012.86
5.2.90.0200.04012.86
5.2.80.0300.02712.86
5.2.70.0200.04712.86
5.2.60.0200.04012.86
5.2.50.0200.03312.86
5.2.40.0170.03712.86
5.2.30.0230.02712.86
5.2.20.0230.05712.86
5.2.10.0230.03012.86
5.2.00.0170.03312.86
5.1.60.0170.03712.86
5.1.50.0200.04312.86
5.1.40.0200.05012.86
5.1.30.0200.03712.86
5.1.20.0270.04712.86
5.1.10.0230.03712.86
5.1.00.0130.03012.86
5.0.50.0100.03012.86
5.0.40.0130.03712.86
5.0.30.0100.05712.86
5.0.20.0100.04312.86
5.0.10.0070.02712.86
5.0.00.0100.06312.86
4.4.90.0100.03312.86
4.4.80.0130.01712.86
4.4.70.0070.04012.86
4.4.60.0070.04012.86
4.4.50.0070.03012.86
4.4.40.0130.04712.86
4.4.30.0100.02712.86
4.4.20.0130.02712.86
4.4.10.0130.03012.86
4.4.00.0130.04712.86
4.3.110.0070.03012.86
4.3.100.0070.03712.86
4.3.90.0100.02012.86
4.3.80.0100.02312.86
4.3.70.0130.02312.86
4.3.60.0100.03712.86
4.3.50.0170.02312.86
4.3.40.0130.03012.86
4.3.30.0070.03712.86
4.3.20.0070.03712.86
4.3.10.0030.03712.86
4.3.00.0130.01312.86

preferences:
51.08 ms | 400 KiB | 5 Q