我試圖製作一個PHP腳本,它將盡可能快地檢查網站的HTTP狀態。比get_headers()更快的東西()
我目前正在使用get_headers()並從mysql數據庫的200個隨機URL中運行它。
要查看所有200 - 平均需要2分48秒。
有什麼我可以做的,使(它)更快?我知道fsockopen - 它可以在20多個站點上檢查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;
?>
嗨,我也嘗試使用cURL - 就像你發佈的代碼。但它是一樣的,事實上比get_headers()稍長一點; – Clarkey 2012-04-01 12:11:24
嘗試做出多個請求,因爲我給上面的鏈接。例如每次10個請求 – safarov 2012-04-01 12:11:59
+1不錯的一個!我不知道curl擴展可以並行處理請求。 – nnichols 2012-04-01 12:12:33