我想为我的站点创建站点地图。所以在创建网站地图之前,我想知道每个url的状态代码。我已经使用curl选项来扣除状态代码。我的网站上有400多个网址。如果我使用curl,它需要很长时间。
只有我想允许包含状态代码200的url。
你能告诉我任何其他选项来扣除每个网址的状态码吗。
我使用了下面的旋度代码。
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlparam);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 240);
curl_exec($ch);
$curlcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $curlcode;
参考链接
几个月前我遇到了同样的问题。我发现使用这个代码示例来访问我自己的页面状态代码要快得多:
<?php
//
// Checking the status of a web page - funmin.com
//
$server="www.YOUR_WEBSITE.com";
function sockAccess($page)
{
$errno = "";
$errstr = "";
$fp = 0;
global $server;
$fp = fsockopen($server, 80, $errno, $errstr, 30);
if ($fp===0)
{
die("Error $errstr ($errno)");
}
$out = "GET /$page HTTP/1.1rn";
$out .= "Host: $serverrn";
$out .= "Connection: Closernrn";
fwrite($fp,$out);
$content = fgets($fp);
$code = trim(substr($content,9,4));
fclose($fp);
return intval($code);
}
?>
更多文件可在此处找到:http://www.forums.hscripts.com/viewtopic.php?f=11&t=4217