2013-10-10 59 views
2

我有一个脚本,用于检查文件是否存在于另一台服务器上,其中get_headers。我在一台服务器上运行了两台服务器,另一台服务器从get_headers得到一个空的响应。PHP:get_headers空结果

我的代码:

$myurl='http://stackoverflow.com/'; 
$header = get_headers($myurl); 
print_r($header); 

PHP版本

PHP 5.3.3-7+squeeze14 with Suhosin-Patch (cli) (built: Aug 6 2012 14:18:06) 
Copyright (c) 1997-2009 The PHP Group 
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies 

解决方案:

没有确定那是什么,我的Apache日志已满这些错误 failed to open stream: php_network_getaddresses: getaddrinfo failed: System error

后的重启后它全部消失,并且get_headers正在工作。

+0

看起来像phpwtf,也许使用curl来代替? – Peter

+0

我也会使用curl,以便您可以执行HEAD请求,或使用'stream_context_set_default()'使HTTP请求使用HEAD。如果您只对标题感兴趣,没有理由使用完整的GET来做到这一点。 –

回答

0

检查allow_url_fopen是否打开。

php - info | grep allow_url_fopen

+0

php --info | grep allow_url_fopen allow_url_fopen => On => On – kkgzjjmj