php:与HTTP头不一致的行为

php:与HTTP头不一致的行为,php,url,http-headers,http-status-code-404,httpresponse,Php,Url,Http Headers,Http Status Code 404,Httpresponse,我正在测试同一个域上的许多链接,看看它们是否存在。我正在使用以下代码: function get_http_response_code($url) { $headers = get_headers($url); return substr($headers[0], 9, 3); } function getURLs() { foreach($allResults as $result) { $tempURL = 'http://www.doma.in/f

我正在测试同一个域上的许多链接,看看它们是否存在。我正在使用以下代码:

function get_http_response_code($url)
{
    $headers = get_headers($url);
    return substr($headers[0], 9, 3);
}

function getURLs()
{
    foreach($allResults as $result)
    {
    $tempURL = 'http://www.doma.in/foo/'.$result.'/bar';
    if(get_http_response_code($tempURL) != "404" && get_http_response_code($tempURL) != "500")
    {
        $URLs[] = $tempURL;
    }
    else
    {
        echo $tempURL.' could not be reached<br />';
    }
    return $URLs;
}
$URLs = getURLs();
函数获取\u http\u响应\u代码($url)
{
$headers=get_headers($url);
返回substr($headers[0],9,3);
}
函数getURLs()
{
foreach($allResults作为$result)
{
$tempURL=http://www.doma.in/foo/“.$result.”/bar“;
如果(获取http响应代码($tempURL)!=“404”&获取http响应代码($tempURL)!=“500”)
{
$URL[]=$tempURL;
}
其他的
{
echo$tempURL.“无法访问
”; } 返回$URL; } $URL=getURL();

问题是,在存在的数百个URL中,
$URL
数组包含不存在的URL(404);有时是两个,有时是四个,但每次都会产生HTTP/1.0 404 Not Found错误。为什么会出现这种差异?是否有应该设置的超时?请提供任何帮助。

据我从您的代码中了解,问题出在变量
$url
试试这个

...
foreach($allResults as $result)
{
    $tempURL = 'http://www.doma.in/foo/'.$result['url'].'/bar';
...

$url
更改为
$result

您的getURLs函数作用域中没有$url变量。谢谢,输入错误,已编辑。此代码已大量编辑,但问题仍然是我如何描述它。您能看到服务器日志中的错误吗?那会是哪个日志?我正在使用Apache。代码本身可以工作。我在使用HTTP时遇到问题标题。