3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @author Oscar Casajuana a.k.a. elboletaire <elboletaire {at} underave {dot} net> */ /* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/> */ class Crawler { private $depth = 2; private $url; private $results = array(); private $same_host = false; private $host; public function setDepth($depth) { $this->depth = $depth; } public function setHost($host) { $this->host = $host; } public function getResults() { return $this->results; } public function setSameHost($same_host) { $this->same_host = $same_host; } public function setUrl($url) { $this->url = $url; $this->setHost($this->getHostFromUrl($url)); } public function __construct($url = null, $depth = null, $same_host = false) { if (!empty($url)) { $this->setUrl($url); } if (isset($depth) && !is_null($depth)) { $this->setDepth($depth); } $this->setSameHost($same_host); } public function crawl() { if (empty($this->url)) { throw new Exception('URL must be set'); } $this->_crawl($this->url, $this->depth); return $this->results; } private function _crawl($url, $depth) { static $seen = array(); if (empty($url)) return; if (!$url = $this->buildUrl($this->url, $url)) { return; } if ($depth === 0 || isset($seen[$url])) { return; } $seen[$url] = true; $dom = new DOMDocument('1.0'); @$dom->loadHTMLFile($url); $this->results[] = array( 'url' => $url, // 'content' => $dom->saveHTML() ); $anchors = $dom->getElementsByTagName('a'); foreach ($anchors as $element) { if (!$href = $this->buildUrl($url, $element->getAttribute('href'))) { continue; } $this->_crawl($href, $depth - 1); } return $url; } private function buildUrl($url, $href) { if (0 !== strpos($href, 'http')) { if (0 === strpos($href, 'javascript:') || 0 === strpos($href, '#')) { return false; } $path = '/' . ltrim($href, '/'); if (extension_loaded('http')) { $new_href = http_build_url($url, array('path' => $path), HTTP_URL_REPLACE, $parts); } else { $parts = parse_url($url); $new_href = $this->buildUrlFromParts($parts); $new_href .= $path; } // Relative urls... (like ./viewforum.php) if (0 === strpos($href, './') && !empty($parts['path'])) { // If the path isn't really a path (doesn't end with slash)... if (!preg_match('@/$@', $parts['path'])) { $path_parts = explode('/', $parts['path']); array_pop($path_parts); $parts['path'] = implode('/', $path_parts) . '/'; } $new_href = $this->buildUrlFromParts($parts) . $parts['path'] . ltrim($href, './'); } $href = $new_href; } $href = rtrim($href, '/'); if ($this->same_host && $this->host != $this->getHostFromUrl($href)) { return false; } return $href; } private function buildUrlFromParts($parts) { $new_href = $parts['scheme'] . '://'; if (isset($parts['user']) && isset($parts['pass'])) { $new_href .= $parts['user'] . ':' . $parts['pass'] . '@'; } $new_href .= $parts['host']; if (isset($parts['port'])) { $new_href .= ':' . $parts['port']; } return $new_href; } private function getHostFromUrl($url) { $parts = parse_url($url); preg_match("@([^/.]+)\.([^.]{2,6}(?:\.[^.]{2,3})?)$@", $parts['host'], $host); return array_shift($host); } } Crawler::crawl("http://google.com");

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.0140.00418.55
8.3.50.0070.01316.48
8.3.40.0150.00018.78
8.3.30.0040.01218.63
8.3.20.0000.00920.35
8.3.10.0050.00323.70
8.3.00.0000.00919.80
8.2.180.0130.00616.75
8.2.170.0110.00722.96
8.2.160.0060.01220.47
8.2.150.0000.00824.18
8.2.140.0000.00824.66
8.2.130.0080.00026.16
8.2.120.0030.00617.63
8.2.110.0040.00722.20
8.2.100.0090.00317.63
8.2.90.0030.00619.14
8.2.80.0060.00317.97
8.2.70.0040.00417.63
8.2.60.0000.00817.93
8.2.50.0090.00018.07
8.2.40.0040.00419.35
8.2.30.0030.00519.64
8.2.20.0070.00017.76
8.2.10.0000.00818.02
8.2.00.0030.00618.21
8.1.270.0050.00320.33
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0060.00323.84
8.1.230.0040.00717.48
8.1.220.0030.00517.74
8.1.210.0000.00818.77
8.1.200.0040.00417.35
8.1.190.0030.00617.35
8.1.180.0000.00818.10
8.1.170.0030.00618.68
8.1.160.0000.00721.91
8.1.150.0000.00718.93
8.1.140.0050.00517.37
8.1.130.0070.00017.64
8.1.120.0000.00817.29
8.1.110.0080.00017.32
8.1.100.0050.00217.30
8.1.90.0080.00017.30
8.1.80.0000.00717.42
8.1.70.0030.00317.40
8.1.60.0030.00617.46
8.1.50.0040.00417.52
8.1.40.0030.00617.54
8.1.30.0050.00317.55
8.1.20.0030.00617.62
8.1.10.0050.00317.60
8.1.00.0080.00017.44
8.0.300.0000.00818.77
8.0.290.0020.00516.88
8.0.280.0000.00718.32
8.0.270.0050.00217.21
8.0.260.0000.00617.31
8.0.250.0070.00017.04
8.0.240.0070.00016.89
8.0.230.0070.00016.90
8.0.220.0030.00316.84
8.0.210.0040.00416.94
8.0.200.0000.00717.04
8.0.190.0080.00017.00
8.0.180.0080.00016.84
8.0.170.0040.00416.90
8.0.160.0050.00317.07
8.0.150.0070.00016.87
8.0.140.0000.00716.80
8.0.130.0000.00813.48
8.0.120.0060.00316.93
8.0.110.0070.00016.86
8.0.100.0040.00416.86
8.0.90.0050.00216.90
8.0.80.0030.01716.84
8.0.70.0050.00216.88
8.0.60.0000.00716.90
8.0.50.0000.00816.97
8.0.30.0150.00717.17
8.0.20.0060.01317.40
8.0.10.0040.00417.13
8.0.00.0110.00616.83
7.4.330.0030.00315.08
7.4.320.0050.00316.54
7.4.300.0030.00316.61
7.4.290.0030.00316.59
7.4.280.0080.00016.38
7.4.270.0030.00316.52
7.4.260.0040.00416.44
7.4.250.0030.00516.55
7.4.240.0030.00416.51
7.4.230.0000.00716.61
7.4.220.0110.00716.50
7.4.210.0060.01016.53
7.4.200.0020.00516.62
7.4.160.0100.00616.36
7.4.150.0090.00917.40
7.4.140.0110.01117.86
7.4.130.0100.00816.66
7.4.120.0060.01116.47
7.4.110.0140.00416.53
7.4.100.0170.00816.53
7.4.90.0140.00316.54
7.4.80.0090.00919.39
7.4.70.0060.01216.44
7.4.60.0090.00616.42
7.4.50.0030.00516.55
7.4.40.0180.00016.50
7.4.30.0110.01416.72
7.4.00.0100.00714.99
7.3.330.0000.00613.44
7.3.320.0050.00013.42
7.3.310.0000.00716.32
7.3.300.0040.00416.38
7.3.290.0080.00016.46
7.3.280.0120.01016.42
7.3.270.0100.00717.40
7.3.260.0090.00916.51
7.3.250.0130.00916.42
7.3.240.0090.00816.61
7.3.230.0160.00016.39
7.3.210.0090.00916.48
7.3.200.0110.00816.55
7.3.190.0070.01316.61
7.3.180.0060.00916.47
7.3.170.0090.00916.50
7.3.160.0080.00916.41
7.2.330.0110.00616.75
7.2.320.0120.00916.58
7.2.310.0160.00516.39
7.2.300.0100.00616.71
7.2.290.0060.01616.29
7.2.60.0240.00416.57
7.2.00.0040.00419.40
7.1.200.0090.00615.62
7.1.100.0080.00417.86
7.1.70.0080.00417.07
7.1.60.0030.02220.03
7.1.50.0060.00916.77
7.1.00.0000.09722.25
7.0.200.0070.00016.56
7.0.60.0030.04720.08
7.0.50.0100.08017.93
7.0.40.0000.09020.10
7.0.30.0270.07720.21
7.0.20.0200.08320.17
7.0.10.0070.08720.22
7.0.00.0030.07320.32
5.6.280.0030.05321.11
5.6.210.0070.06720.52
5.6.200.0100.06718.31
5.6.190.0070.04720.57
5.6.180.0170.04320.66
5.6.170.0200.05720.46
5.6.160.0000.04720.46
5.6.150.0070.04318.25
5.6.140.0030.04718.22
5.6.130.0170.06718.20
5.6.120.0030.04021.02
5.6.110.0100.06321.03
5.6.100.0130.06321.15
5.6.90.0100.06321.12
5.6.80.0100.07020.48
5.5.350.4330.04320.45
5.5.340.0100.07717.97
5.5.330.0070.04320.27
5.5.320.0300.03720.27
5.5.310.0400.05720.26
5.5.300.0070.08017.98
5.5.290.0170.06317.98
5.5.280.0030.04020.89
5.5.270.0070.08720.91
5.5.260.0130.08320.88
5.5.250.0100.07020.70
5.5.240.0030.06720.23
5.4.450.0200.06319.14
5.4.440.0200.06019.63
5.4.430.0130.06719.62
5.4.420.0200.05019.61
5.4.410.0100.07019.36
5.4.400.0100.05719.26
5.4.390.0100.06719.28
5.4.380.0230.05019.06
5.4.370.0370.05018.87
5.4.360.0100.06019.15
5.4.350.0070.06019.14
5.4.340.0200.04719.39
5.4.320.0270.04719.00
5.4.310.0100.05719.12
5.4.300.0200.06019.05
5.4.290.0130.06019.25
5.4.280.0270.04018.98
5.4.270.0170.04718.98
5.4.260.0170.04719.14
5.4.250.0170.05019.30
5.4.240.0230.05019.30
5.4.230.0200.04718.84
5.4.220.0130.06319.00
5.4.210.0200.04719.14
5.4.200.0230.04719.14
5.4.190.0200.04719.14
5.4.180.0170.05019.25
5.4.170.0170.05718.86
5.4.160.0130.06019.13
5.4.150.0230.07019.12
5.4.140.0130.06316.53
5.4.130.0170.05716.35
5.4.120.0230.04316.35
5.4.110.0130.05316.42
5.4.100.0100.05316.41
5.4.90.0130.05016.27
5.4.80.0070.06716.65
5.4.70.0330.06016.52
5.4.60.0230.07016.44
5.4.50.0100.04016.56
5.4.40.0230.06716.55
5.4.30.0000.04016.48
5.4.20.0200.04016.35
5.4.10.0430.05716.44

preferences:
43.44 ms | 400 KiB | 5 Q