我正在尝试制作一个 PHP 脚本,以尽快检查网站的 HTTP 状态。
我目前正在使用 get_headers() 并在来自 mysql 数据库的 200 个随机 URL 的循环中运行它。
检查所有 200 个 - 平均需要 2m 48s。
我能做些什么来让它(很多)更快?
(我知道 fsockopen - 它可以在 20 年代检查 200 个站点上的端口 80 - 但它与请求 http 状态代码不同,因为服务器可能会在端口上响应 - 但可能无法正确加载网站等)
这是代码..
<?php
function get_httpcode($url) {
$headers = get_headers($url, 0);
// Return http status code
return substr($headers[0], 9, 3);
}
###
## Grab task and execute it
###
// Loop through task
while($data = mysql_fetch_assoc($sql)):
$result = get_httpcode('http://'.$data['url']);
echo $data['url'].' = '.$result.'<br/>';
endwhile;
?>