【发布时间】:2014-06-03 12:38:35
【问题描述】:
检查链接是否可用的 Curl 函数重复了大约 600 次,大约需要 20 分钟,我记得一年前做了一些事情,它在 30 秒内开始做同样的事情
//return the availability of link
function check($url){
$agent = 'Mozilla/4.0 (compatible;)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url );
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 60000);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 60000);
curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:11107');
// set start time
$mtime = microtime();
$mtime = explode(' ', $mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
$page = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo curl_error($ch); echo '<br />';
// set end time
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
curl_close($ch);
echo "This script executed in " .$totaltime. " seconds. With ".$httpcode." Status.";
if($httpcode>=100 && $httpcode<600) return $httpcode; else return 0;
}
我用这个函数调用
$new_pr = check($url);
【问题讨论】:
标签: php performance curl