3v4l.org

run code in 300+ PHP versions simultaneously
<?php //爬虫程序,统计成功,失败 /* $res=fetch("http://map.baidu.com/place/bd180e5585e0f428bd45de9a"); file_put_contents("log.txt", $res["header"]["http_code"]." ".$res["header"]["total_time"]." ".$res["content"]); exit; */ $MENU_COUNT = array( "1"=>225,"2"=>45,"3"=>65,"4"=>99,"5"=>17,"6"=>168,"7"=>91, "8"=>57,"9"=>46,"10"=>92,"11"=>72,"12"=>66,"13"=>72,"14"=>45, "15"=>15 ); $EVERY = 50 * 50 ; $RAND = 40 ; //list,detail(all_cost,pre_cost,all,defeate,success,success_cost,defeate_cost,success_pre,defeate_pre) $ALL_RESULT = array(); $handle = fopen("get_page.txt",'a'); fwrite($handle , "URL KIND COST FLAG(0失败,1)" ); for( $i=0; $i < $RAND; $i++ ){ $have_url = 0; $k = 0; $m = rand(1, 15); $n = rand(1, $MENU_COUNT[$m]); $url = "http://map.baidu.com/place/beijing/".$m."/".$n; $url_list_handle_w = fopen("get_page_url.txt",'w'); $url_list_handle_r = fopen("get_page_url.txt",'r'); $res = getPage($url, "list", &$have_url, z$EVERY ,$url_list_handle_w); initRes($res, $handle, &$ALL_RESULT, $url); if(!$res["flag"] || !$res['no_url'] ){ //如果失败,或者成功但是页面中没有 列表或详情页链接 $i--; @fclose($url_list_handle_w); @fclose($url_list_handle_r); continue; } while (!feof($url_list_handle_r)) { $buffer = fgets($url_list_handle_r); if(!$buffer || $k>= $EVERY ){ break; } $k++; $buffer=explode(" ", $buffer); $res = getPage($buffer[1], $buffer[0] , &$have_url, $EVERY ,$url_list_handle_w); initRes($res,$handle,&$ALL_RESULT, rtrim($buffer[2]) ); } @fclose($url_list_handle_w); @fclose($url_list_handle_r); } $ALL_RESULT['list']['pre_cost'] = $ALL_RESULT['list']["all_cost"]/$ALL_RESULT['list']["all"]; $ALL_RESULT['list']['success_pre'] = $ALL_RESULT['list']["success_cost"]/$ALL_RESULT['list']["success"]; if( $ALL_RESULT['list']["defeate"] ){ $ALL_RESULT['list']['defeate_pre'] = $ALL_RESULT['list']["defeate_cost"]/$ALL_RESULT['list']["defeate"]; } $ALL_RESULT['detail']['pre_cost'] = $ALL_RESULT['detail']["all_cost"]/$ALL_RESULT['detail']["all"]; $ALL_RESULT['detail']['success_pre'] = $ALL_RESULT['detail']["success_cost"]/$ALL_RESULT['detail']["success"]; if($ALL_RESULT['detail']["defeate"]){ $ALL_RESULT['detail']['defeate_pre'] = $ALL_RESULT['detail']["defeate_cost"]/$ALL_RESULT['detail']["defeate"]; } $str="\nKIND 302 ALL ALL_COST PER SUCCESS DEFEATE SUCCESS_COST DEFEATE_COST SUCCESS_PRE DETEATE_PRE"; fwrite( $handle,$str ); foreach ($ALL_RESULT as $key => $value) { $tem=array($key,$value['302'],$value['all'],$value['all_cost'],$value['pre_cost'],$value['success'],intval($value['defeate']),$value['success_cost'],$value['defeate_cost'],$value['success_pre'],$value['defeate_pre']); fwrite($handle,"\n".join(" ",$tem)); } fclose($handle); function initRes($res,$handle,$allres,$from){ fwrite($handle,"\n".$res['url']." ".$from." ".$res['kind']." ".$res['header']["total_time"]." ".$res['flag']." ".$res["http_code"]." ".$res["no_url"]); if($res["http_code"] == "302"){ $allres[$res['kind']]['302']++; return; } $allres[$res['kind']]['all']++; $allres[$res['kind']]['all_cost'] += $res['header']["total_time"]; if(!$res["flag"]){ $allres[$res['kind']]['defeate']++; $allres[$res['kind']]['defeate_cost'] += $res['header']["total_time"]; }else{ $allres[$res['kind']]['success']++; $allres[$res['kind']]['success_cost'] += $res['header']["total_time"]; } } function getPage($url,$kind,$have,$all,$handle){ $res = fetch($url); $result['header'] = $res["header"]; if( $res["header"]["url"] != $url ){ $result["http_code"] = "302"; }else{ $result["http_code"] = $res["header"]["http_code"]; } $result['kind'] = $kind; $result['url'] = $url; if( $res == -500 ){ $result['flag'] = 0; return $result; } $result['flag'] = 1; if( $have >= $all ){ @fclose($handle); $result['no_url'] = 2; return $result; } $result['url_list'] = array(); preg_match_all("/<a.*?href=[\"\'](.*?)[\"\'].*?>/", $res['content'], $matches, PREG_PATTERN_ORDER); for($i=0 ,$k=0 ; $i < count($matches[1]) && $k < 20; $i++){ $matches[1][$i]=substr($matches[1][$i],stripos($matches[1][$i],'/place')+6); $tem_url="http://map.baidu.com/place".$matches[1][$i]; if($tem_url==$url){ continue; } if(preg_match("/^\/\w{24}$/i", $matches[1][$i]) != 0 ){ $k++; $result['url_list'][]="detail http://map.baidu.com/place".$matches[1][$i]." ".$url; }else if(preg_match("/^\/[^\/]{1,20}\/\d{1,10}\/\d{1,10}/i", $matches[1][$i]) != 0 ){ $k++; $result['url_list'][]="list http://map.baidu.com/place".$matches[1][$i]." ".$url; } } $k = count($result['url_list']); $result['no_url'] = 1; if( $k <= 0 ){ $result['no_url'] = 0; }else{ fwrite($handle,join("\n" , $result['url_list'])."\n"); } $have += $k; return $result; } function fetch($url) { $c = curl_init($url); if (!$c) { return -500; } curl_setopt($c, CURLOPT_MAXREDIRS, 3); curl_redir_exec($c); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); curl_setopt($c,CURLOPT_USERAGENT,"baiduspider"); curl_setopt($c, CURLOPT_AUTOREFERER, true); curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 50); curl_setopt($c, CURLOPT_TIMEOUT, 50); $rst_str = curl_exec($c); $header = curl_getinfo($c); curl_close($c); if ($rst_str == false) { return -500; } return array('content' => $rst_str , "header" => $header); } function curl_redir_exec($ch,$debug = "") { static $curl_loops = 0; static $curl_max_loops = 20; if ($curl_loops++ >= $curl_max_loops) { $curl_loops = 0; return FALSE; } curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $debbbb = $data; list($header, $data) = explode("\n\n", $data, 2); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code == 301 || $http_code == 302) { $matches = array(); preg_match('/Location:(.*?)\n/', $header, $matches); $url = @parse_url(trim(array_pop($matches))); if (!$url) { $curl_loops = 0; return $data; } $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query']?'?'.$url['query']:''); @curl_setopt($ch, CURLOPT_URL, $new_url); return curl_redir_exec($ch); } else { $curl_loops=0; return $debbbb; } } ?>

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)
5.4.340.0100.03511.99
5.4.320.0090.03612.48
5.4.310.0050.04012.47
5.4.300.0070.03712.48
5.4.290.0080.03712.48
5.4.280.0090.03612.37
5.4.270.0050.04012.37
5.4.260.0070.03812.37
5.4.250.0110.04012.37
5.4.240.0050.03612.37
5.4.230.0060.04512.36
5.4.220.0080.03412.36
5.4.210.0070.05112.36
5.4.200.0610.05212.36
5.4.190.0570.03712.36
5.4.180.0110.03812.36
5.4.170.0070.03712.37
5.4.160.0120.03412.37
5.4.150.0050.03712.36
5.4.140.0120.04612.05
5.4.130.0080.03412.03
5.4.120.0070.03811.99
5.4.110.0080.03411.99
5.4.100.0060.03511.99
5.4.90.0100.04011.98
5.4.80.0040.04011.98
5.4.70.0040.03611.98
5.4.60.0050.03411.98
5.4.50.0080.03211.98
5.4.40.0040.03511.97
5.4.30.0050.03711.96
5.4.20.0090.04111.96
5.4.10.0060.03411.96
5.4.00.0050.03611.45
5.3.290.0090.03912.80
5.3.280.0410.03812.71
5.3.270.0270.03812.72
5.3.260.0420.03912.72
5.3.250.0580.04512.72
5.3.240.0290.03812.72
5.3.230.0290.03812.70
5.3.220.0110.04412.68
5.3.210.0100.03912.68
5.3.200.0070.03612.68
5.3.190.0040.04012.67
5.3.180.0080.03412.67
5.3.170.0050.03712.67
5.3.160.0050.03712.67
5.3.150.0070.03612.67
5.3.140.0050.03712.66
5.3.130.0070.03912.65
5.3.120.0040.04112.66
5.3.110.0050.04012.65
5.3.100.0060.03612.12
5.3.90.0080.03512.08
5.3.80.0050.03912.08
5.3.70.0070.03512.07
5.3.60.0040.03812.06
5.3.50.0060.03612.00
5.3.40.0060.03612.00
5.3.30.0070.03411.96
5.3.20.0080.03311.73
5.3.10.0060.03411.70
5.3.00.0080.03311.68
5.2.170.0050.0309.20
5.2.160.0060.0279.20
5.2.150.0040.0309.20
5.2.140.0050.0309.19
5.2.130.0070.0269.15
5.2.120.0050.0289.16
5.2.110.0010.0329.16
5.2.100.0040.0299.15
5.2.90.0070.0269.15
5.2.80.0040.0309.15
5.2.70.0040.0309.15
5.2.60.0040.0309.10
5.2.50.0280.0349.07
5.2.40.0240.0329.05
5.2.30.0310.0379.03
5.2.20.0240.0339.01
5.2.10.0200.0348.94
5.2.00.0250.0348.80
5.1.60.0190.0308.08
5.1.50.0180.0358.08
5.1.40.0300.0228.07
5.1.30.0240.0268.41
5.1.20.0270.0288.43
5.1.10.0190.0258.16
5.1.00.0190.0278.16
5.0.50.0240.0186.64
5.0.40.0230.0196.51
5.0.30.0220.0416.32
5.0.20.0200.0196.29
5.0.10.0160.0216.26
5.0.00.0300.0276.26
4.4.90.0150.0164.78
4.4.80.0140.0144.75
4.4.70.0160.0164.76
4.4.60.0150.0164.75
4.4.50.0080.0164.77
4.4.40.0250.0244.71
4.4.30.0180.0154.76
4.4.20.0050.0154.84
4.4.10.0030.0154.85
4.4.00.0210.0224.76
4.3.110.0110.0194.67
4.3.100.0200.0194.67
4.3.90.0190.0144.63
4.3.80.0180.0274.58
4.3.70.0150.0144.63
4.3.60.0110.0164.63
4.3.50.0150.0124.63
4.3.40.0120.0254.54
4.3.30.0120.0163.30
4.3.20.0150.0143.28
4.3.10.0090.0193.24
4.3.00.0030.0206.85

preferences:
142.22 ms | 1394 KiB | 7 Q