3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('Europe/Athens'); // Create connection $conn = new mysqli("mysql.freehostia.com", "dimpou5_forum", "stella_0", "dimpou5_forum", 3306); $conn->set_charset("utf8"); $tablePrefix = ""; // Check connection if ($conn->connect_error) die("Connection failed: " . $conn->connect_error); /* $rows = array(); $sql = "SELECT * FROM structure"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { //echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>"; $rows[] = $row; } } else { echo "0 results"; } $count_last_category = 0; $tree = buildTree($rows); $list_dom = print_ols($tree); echo $count_last_category; echo $list_dom; echo "\n"; echo date("d-m-Y") . "\n"; echo strtotime(date("d-m-Y")) . "\n"; print_r( skroutz_getPriceFromLink("http://www.skroutz.gr/s/6535417/Manta-MS1701.html")); */ $sql = "SELECT * FROM ".$tablePrefix."structure WHERE path LIKE '%kinhta%' LIMIT 1"; $result = $conn->query($sql); if ($result->num_rows > 0) { $row = $result->fetch_assoc(); $subcategory_url = $row['scheme'] . "://" . $row['host'] . $row['path']; skroutz_updateSubcategoriesProducts($subcategory_url, $conn, 1); echo "<span style='font-size: 15; font-weight: bold; color: green'>DONE! :)</span>"; } else { echo "0 results"; } /** apo edw 3ekiname */ function skroutz_updateSubcategoriesProducts($url, $connection, $sleep){ $numOfPages = skroutz_getNumOfPages($url); for ($i=1; $i <= $numOfPages; $i++) { $page_products = skroutz_getPageProducts($url . "?page=" . $i); skroutz_products_insert_update($page_products, $connection); sleep($sleep); } } //voithitiki //edw metrame poses selides exei.. //pernoume ola ta li pou einai mesa se class 'paginator' (einai apo dio fores, alla den mas niazei) //giati to proteleutaio theloume function skroutz_getNumOfPages($url){ $output = file_get_contents($url); $dom_output = new DomDocument(); @$dom_output->loadHTML(mb_convert_encoding($output, 'HTML-ENTITIES', 'UTF-8')); $finder = new DomXPath($dom_output); $nodes = $finder->query("//*[contains(@class, 'paginator')]//li"); return $nodes->item($nodes->length-2)->nodeValue; } function skroutz_getPageProducts($url){ $output = file_get_contents($url); $dom_output = new DomDocument(); @$dom_output->loadHTML(mb_convert_encoding($output, 'HTML-ENTITIES', 'UTF-8')); $finder = new DomXPath($dom_output); $products = array(); $nodes = $finder->query("//*[contains(@id, 'sku_list')]//li[contains(@class, 'line')]"); foreach($nodes as $i => $node){ $name = $finder->query("div[contains(@class, 'details')]/h2/a", $node)->item(0); $link = parse_url($name->getAttribute('href')); if(!isset($link['host'])){ $link['scheme'] = "http"; $link['host'] = "www.skroutz.gr"; } $price = trim($finder->query("p[contains(@class, 'price')]//a", $node)->item(0)->nodeValue); $price = str_replace(array(","," €"), "", $price); $products[$i]['id'] = skroutz_getProductIdFromUrl($name->getAttribute('href')); $products[$i]['category_id'] = skroutz_getCategoryIdFromUrl($url); $products[$i]['name'] = trim($name->nodeValue); $products[$i]['price']['date'] = date("Ymd"); $products[$i]['price']['value'] = $price; $products[$i]['scheme'] = $link['scheme']; $products[$i]['host'] = $link['host']; $products[$i]['path'] = $link['path']; } return $products; } /* skroutz_products_insert_update: pernei enan pinaka tis parakatw morfis kai ton vazei mesa ston pinaka 'products' KAI 'prices' * Array * ( * [0] => Array * ( * [id] => 6535417 * [category_id] => 40 * [name] => Manta MS1701 * [price] => Array * ( * [date] => 20151118 * [value] => 1580 * ) * * [scheme] => http * [host] => www.skroutz.gr * [path] => /s/6535417/Manta-MS1701.html * ) * [1] => Array * ( * .... * ) **/ function skroutz_products_insert_update($array, $connection){ global $tablePrefix; foreach ($array as $key => $value) { $sql = "INSERT INTO ".$tablePrefix."products (id, category_id, name, scheme, host, path) VALUES ('$value[id]', '$value[category_id]', '" . mysqli_real_escape_string($connection ,$value['name']) . "', '$value[scheme]', '$value[host]', '$value[path]') ON DUPLICATE KEY UPDATE category_id='$value[category_id]', name='" . mysqli_real_escape_string($connection, $value['name']) . "'"; if ($connection->query($sql) === TRUE) { echo "$value[name] .................successfully<br>\n"; } else { echo "Error: " . $sql . "<br>" . $connection->error; } $sql = "INSERT INTO ".$tablePrefix."prices (id, date, price, lastUpdate) VALUES ('$value[id]', '".$value["price"]["date"]."', '".$value["price"]["value"]."', NOW()) ON DUPLICATE KEY UPDATE price='".$value["price"]["value"]."', lastUpdate=NOW()"; if ($connection->query($sql) === TRUE) { echo "$value[name] .................successfully<br>\n"; } else { echo "Error: " . $sql . "<br>" . $connection->error; } } } /* function skroutz_getPageProducts($url){ $output = file_get_contents($url); $dom_output = new DomDocument(); @$dom_output->loadHTML(mb_convert_encoding($output, 'HTML-ENTITIES', 'UTF-8')); $finder = new DomXPath($dom_output); $products = array(); $nodes = $finder->query("//*[contains(@id, 'sku_list')]//li[contains(@class, 'line')]//h2//a"); foreach($nodes as $i => $node){ $link = parse_url($node->getAttribute('href')); if(!isset($link['host'])){ $link['scheme'] = "http"; $link['host'] = "www.skroutz.gr"; } $products[$i]['id'] = skroutz_getProductIdFromUrl($node->getAttribute('href')); $products[$i]['category_id'] = skroutz_getCategoryIdFromUrl($url); $products[$i]['name'] = trim($node->nodeValue); $products[$i]['scheme'] = $link['scheme']; $products[$i]['host'] = $link['host']; $products[$i]['path'] = $link['path']; } return $products; } */ $conn->close(); //den xrisimopoieite pros to paron function skroutz_getPriceFromLink($link){ $link_json = substr($link, 0, -5) . "/price_graph.json"; $output = json_decode(file_get_contents($link_json)); $index = count($output->min_price->recent) - 1; $current_price = $output->min_price->recent[$index]; return $current_price; } function print_ols($array){ global $count_last_category; $return = "<ol>"; foreach ($array as $key => $value) { $return .= "<li value='$value[id]'>"; $return .= $value['name']; if(isset($value['children'])) $return .= print_ols($value['children']); else $count_last_category++; $return .= "</li>"; } $return .= "</ol>"; return $return; } //http://stackoverflow.com/questions/8587341/recursive-function-to-generate-multidimensional-array-from-database-result function buildTree(array $elements, $parentId = 0) { $branch = array(); foreach ($elements as $element) { if ($element['parent_id'] == $parentId) { $children = buildTree($elements, $element['id']); if ($children) { $element['children'] = $children; } $branch[] = $element; } } return $branch; } //voithitiki function skroutz_getCategoryIdFromUrl($url){ $parts = explode('/', $url); foreach ($parts as $key => $value) { if ($value == "c"){ return $parts[$key + 1]; } } return 0; //an ftasei mexri edw, den exei parent } //voithitiki function skroutz_getProductIdFromUrl($url){ $parts = explode('/', $url); foreach ($parts as $key => $value) { if ($value == "s"){ return $parts[$key + 1]; } } return 0; //an ftasei mexri edw, den exei parent } ?>

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.0120.00618.84
8.3.30.0040.01118.92
8.3.20.0040.00420.16
8.3.10.0040.00423.48
8.3.00.0040.00419.38
8.2.170.0060.00922.96
8.2.160.0040.01120.37
8.2.150.0030.00524.18
8.2.140.0050.00324.66
8.2.130.0060.00320.47
8.2.120.0080.00026.35
8.2.110.0110.01120.51
8.2.100.0040.00817.78
8.2.90.0050.00319.21
8.2.80.0000.00817.97
8.2.70.0070.00317.75
8.2.60.0000.00917.93
8.2.50.0030.00618.07
8.2.40.0000.00819.51
8.2.30.0080.00020.71
8.2.20.0000.00917.82
8.2.10.0080.00017.96
8.2.00.0040.00418.14
8.1.270.0070.01423.97
8.1.260.0000.00828.09
8.1.250.0000.00828.09
8.1.240.0060.00623.70
8.1.230.0120.00022.55
8.1.220.0040.00417.79
8.1.210.0040.00418.77
8.1.200.0040.00417.48
8.1.190.0000.00817.76
8.1.180.0080.00018.10
8.1.170.0040.00418.62
8.1.160.0040.00421.95
8.1.150.0030.00618.84
8.1.140.0030.00519.50
8.1.130.0040.00417.57
8.1.120.0040.00417.51
8.1.110.0030.00617.46
8.1.100.0040.00417.50
8.1.90.0000.00717.38
8.1.80.0040.00417.54
8.1.70.0070.00017.42
8.1.60.0030.00717.43
8.1.50.0030.00517.41
8.1.40.0030.00517.46
8.1.30.0000.00817.72
8.1.20.0040.00417.57
8.1.10.0030.00517.60
8.1.00.0030.00517.54
8.0.300.0030.00518.77
8.0.290.0040.00416.75
8.0.280.0040.00418.48
8.0.270.0040.00417.29
8.0.260.0030.00317.36
8.0.250.0030.00317.06
8.0.240.0070.00016.98
8.0.230.0040.00416.93
8.0.220.0040.00416.89
8.0.210.0000.00816.88
8.0.200.0030.00316.93
8.0.190.0040.00417.05
8.0.180.0000.00817.02
8.0.170.0060.00316.96
8.0.160.0000.00717.07
8.0.150.0050.00516.89
8.0.140.0040.00416.77
8.0.130.0070.00013.48
8.0.120.0040.00416.86
8.0.110.0030.00517.04
8.0.100.0040.00417.03
8.0.90.0040.00416.93
8.0.80.0030.01816.98
8.0.70.0000.00716.98
8.0.60.0000.00716.86
8.0.50.0040.00416.76
8.0.30.0140.00317.25
8.0.20.0110.01117.40
8.0.10.0000.00717.03
8.0.00.0110.00616.71
7.4.330.0000.00516.66
7.4.320.0040.00416.55
7.4.300.0030.00316.48
7.4.290.0070.00016.65
7.4.280.0030.00616.53
7.4.270.0070.00316.68
7.4.260.0000.00716.48
7.4.250.0040.00416.49
7.4.240.0000.00716.47
7.4.230.0070.00016.43
7.4.220.0210.00716.54
7.4.210.0040.01216.57
7.4.200.0070.00016.70
7.4.160.0130.01016.77
7.4.150.0100.00717.40
7.4.140.0070.01117.86
7.4.130.0130.00716.59
7.4.120.0100.00916.73
7.4.110.0100.00716.48
7.4.100.0100.01316.76
7.4.90.0100.01316.43
7.4.80.0060.01219.39
7.4.70.0030.01316.53
7.4.60.0090.00816.53
7.4.50.0050.00816.48
7.4.40.0000.01716.66
7.4.30.0030.01416.41
7.4.10.0110.00714.91
7.4.00.0070.00914.99
7.3.330.0030.00313.36
7.3.320.0030.00313.46
7.3.310.0000.00716.48
7.3.300.0000.00716.34
7.3.290.0040.01116.41
7.3.280.0110.00616.38
7.3.270.0120.00617.40
7.3.260.0030.01616.56
7.3.250.0090.00916.48
7.3.240.0090.01116.33
7.3.230.0150.00916.66
7.3.210.0160.00316.48
7.3.200.0040.01316.39
7.3.190.0060.01116.47
7.3.180.0100.00716.59
7.3.170.0120.01316.50
7.3.160.0140.01016.31
7.3.130.0070.01115.16
7.3.120.0030.01614.63
7.3.110.0090.01215.02
7.3.100.0070.00714.97
7.3.90.0090.00615.04
7.3.80.0090.00615.10
7.3.70.0120.00314.77
7.3.60.0030.01014.95
7.3.50.0030.00614.93
7.3.40.0000.01614.75
7.3.30.0070.00714.80
7.3.20.0030.01016.67
7.3.10.0110.00316.63
7.3.00.0080.00616.37
7.2.330.0030.01516.39
7.2.320.0170.00016.56
7.2.310.0090.00916.38
7.2.300.0130.00916.54
7.2.290.0100.00716.64
7.2.260.0100.01014.84
7.2.250.0030.01314.81
7.2.240.0030.01015.30
7.2.230.0060.01015.31
7.2.220.0120.00614.99
7.2.210.0100.00615.28
7.2.200.0070.00714.78
7.2.190.0030.01015.20
7.2.180.0060.00914.89
7.2.170.0030.01315.00
7.2.160.0000.00915.04
7.2.150.0000.01416.58
7.2.140.0030.01416.81
7.2.130.0000.01316.71
7.2.120.0050.00816.85
7.2.110.0050.01016.84
7.2.100.0030.01216.77
7.2.90.0070.00716.80
7.2.80.0030.01216.89
7.2.70.0050.01216.67
7.2.60.0070.00816.78
7.2.50.0150.00316.67
7.2.40.0050.01116.85
7.2.30.0060.00916.75
7.2.20.0050.00716.62
7.2.10.0050.00616.62
7.2.00.0040.00917.54
7.1.330.0030.01115.59
7.1.320.0030.01315.51
7.1.310.0090.00615.68
7.1.300.0090.00315.72
7.1.290.0070.00715.76
7.1.280.0070.00415.83
7.1.270.0000.01615.59
7.1.260.0040.01215.86
7.1.250.0050.00815.80
7.1.240.0030.01015.59
7.1.230.0060.00515.63
7.1.220.0030.00915.54
7.1.210.0110.00515.60
7.1.200.0050.00515.70
7.1.190.0050.00515.51
7.1.180.0060.00615.71
7.1.170.0060.00615.67
7.1.160.0080.00715.60
7.1.150.0050.00715.85
7.1.140.0020.01115.68
7.1.130.0050.00815.62
7.1.120.0070.00515.40
7.1.110.0020.01415.66
7.1.100.0010.01216.48
7.1.90.0010.01115.64
7.1.80.0080.00715.85
7.1.70.0090.00516.02
7.1.60.0050.01116.90
7.1.50.0090.00715.98
7.1.40.0050.00715.64
7.1.30.0070.00515.60
7.1.20.0080.00615.45
7.1.10.0030.01015.73
7.1.00.0040.03017.89
7.0.330.0070.00915.33
7.0.320.0080.00615.27
7.0.310.0040.00915.13
7.0.300.0070.00815.39
7.0.290.0030.00815.29
7.0.280.0030.01015.32
7.0.270.0030.00915.32
7.0.260.0040.01015.18
7.0.250.0060.00415.21
7.0.240.0080.00615.32
7.0.230.0040.00515.37
7.0.220.0060.00615.29
7.0.210.0040.00915.27
7.0.200.0060.00515.63
7.0.190.0060.00815.29
7.0.180.0100.00615.32
7.0.170.0090.00515.40
7.0.160.0050.00815.20
7.0.150.0100.00315.17
7.0.140.0050.00715.15
7.0.130.0070.00515.17
7.0.120.0050.00915.21
7.0.110.0020.01015.39
7.0.100.0050.01015.05
7.0.90.0090.00615.33
7.0.80.0100.02316.79
7.0.70.0100.02016.95
7.0.60.0170.01716.90
7.0.50.0240.02717.02
7.0.40.0040.03315.58
7.0.30.0060.02815.63
7.0.20.0070.03515.62
7.0.10.0070.03415.43
7.0.00.0060.03115.63
5.6.400.0000.01414.35
5.6.390.0060.01014.41
5.6.380.0070.01014.27
5.6.370.0050.01114.11
5.6.360.0020.00913.98
5.6.350.0030.01014.08
5.6.340.0040.01114.30
5.6.330.0020.01114.13
5.6.320.0020.01114.20
5.6.310.0040.01214.11
5.6.300.0030.00814.41
5.6.290.0040.00813.97
5.6.280.0070.01416.61
5.6.270.0050.00714.09
5.6.260.0130.00214.32
5.6.250.0050.00714.32
5.6.240.0060.00614.19
5.6.230.0060.01716.26
5.6.220.0030.02016.44
5.6.210.0030.02116.17
5.6.200.0080.02816.43
5.6.190.0090.03016.46
5.6.180.0070.02916.48
5.6.170.0040.03316.51
5.6.160.0100.02616.50
5.6.150.0060.03316.49
5.6.140.0070.02316.68
5.6.130.0060.03316.44
5.6.120.0090.03216.48
5.6.110.0070.03416.42
5.6.100.0070.02816.50
5.6.90.0090.02916.48
5.6.80.0070.03416.16
5.6.70.0010.02316.19
5.6.60.0090.02616.09
5.6.50.0060.02116.08
5.6.40.0090.02916.24
5.6.30.0090.02916.37
5.6.20.0070.02916.29
5.6.10.0040.02816.31
5.6.00.0040.02116.23
5.5.380.0050.00612.71
5.5.370.0070.01615.33
5.5.360.0050.01715.21
5.5.350.0040.01815.05
5.5.340.0070.02615.25
5.5.330.0020.02715.30
5.5.320.0040.02215.20
5.5.310.0060.03115.27
5.5.300.0070.02815.27
5.5.290.0070.03115.21
5.5.280.0070.01915.20
5.5.270.0050.02715.27
5.5.260.0100.02415.41
5.5.250.0030.02115.24
5.5.240.0030.03415.07
5.5.230.0070.03014.94
5.5.220.0060.02915.08
5.5.210.0040.03315.02
5.5.200.0070.03015.18
5.5.190.0030.03314.89
5.5.180.0070.02115.08
5.5.170.0030.00812.49
5.5.160.0060.02115.00
5.5.150.0080.02715.04
5.5.140.0080.02314.76
5.5.130.0040.02915.03
5.5.120.0030.03115.04
5.5.110.0070.02815.00
5.5.100.0080.02814.98
5.5.90.0080.02315.05
5.5.80.0040.03115.01
5.5.70.0070.03015.05
5.5.60.0060.02815.05
5.5.50.0080.02715.04
5.5.40.0090.02614.97
5.5.30.0080.02814.95
5.5.20.0030.03114.93
5.5.10.0090.02615.00
5.5.00.0050.02515.04

preferences:
68.22 ms | 400 KiB | 5 Q