脚本头过早结束:php-cgi-运行CURL脚本时 [英] Premature end of script headers: php-cgi -- While running a CURL script
问题描述
在我再次返回主机之前(再次),他们在以下脚本中给出的唯一错误日志是:
before i go back to the Host (yet again) the only error log they are giving on the below script is:
脚本头过早结束:php-cgi
Premature end of script headers: php-cgi
我正在运行的脚本在其他服务器上可以运行,而我的本地计算机在运行,但是在此perticualr服务器上却给出了错误500:
the scrip i am running which works on other servers and my local machine is but on this perticualr server is giving an error 500:
$ch = curl_init("http://feeds.energydigger.com/headlines.xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$doc = new SimpleXmlElement($data, LIBXML_NOCDATA);
if(isset($doc->channel))
{
parseRSS($doc);
}
function parseRSS($xml)
{
$cnt = 3;
for($i=0; $i<$cnt; $i++)
{
$url = $xml->channel->item[$i]->link;
$title = $xml->channel->item[$i]->title;
$desc = $xml->channel->item[$i]->description;
$date = $xml->channel->item[$i]->pubDate;
echo '<p><a href="'.$url.'">'.$title.'</a><br />'.$date.'</p>';
}
}
有人知道什么可能会产生错误吗?我不能说我以前已经看过这个错误了……我仍在尝试掌握PHP日志.
Does anyone know what may generate the error, I can't say I have seen this one before... i am still trying to get hold of the PHP logs too.
推荐答案
如果引发并没有捕获到异常,并且在PHP设置中, display_errors
= 0,则可能会出现500错误.它由SimpleXML抛出.尝试在 try .. catch
块中用XML操作包装该部分,并查看异常是什么.例如:
You can get a 500 error, if an exception is thrown and not caught, and in PHP settings display_errors
= 0. Most likely it is thrown by SimpleXML. Try wrapping the portion with XML operations in a try .. catch
block and see what the exception is. For example:
$ch = curl_init("http://feeds.energydigger.com/headlines.xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
try
{
$doc = new SimpleXmlElement($data, LIBXML_NOCDATA);
if(isset($doc->channel))
{
parseRSS($doc);
}
function parseRSS($xml)
{
$cnt = 3;
for($i=0; $i<$cnt; $i++)
{
$url = $xml->channel->item[$i]->link;
$title = $xml->channel->item[$i]->title;
$desc = $xml->channel->item[$i]->description;
$date = $xml->channel->item[$i]->pubDate;
echo '<p><a href="'.$url.'">'.$title.'</a><br />'.$date.'</p>';
}
}
}
catch (Exception $e)
{
echo $e -> getMessage();
}
以防万一,此处是有关PHP异常的更多信息.
这篇关于脚本头过早结束:php-cgi-运行CURL脚本时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!