Premature end of script headers: php-cgi -- While running a CURL script -
before go host (yet again) error log giving on below script is:
premature end of script headers: php-cgi
the scrip running works on other servers , local machine on perticualr server giving 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>'; } }
does know may generate error, can't have seen 1 before... still trying hold of php logs too.
you can 500 error, if exception thrown , not caught, , in php settings display_errors
= 0. thrown simplexml. try wrapping portion xml operations in try .. catch
block , see exception is. 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(); }
just in case, here's more php exceptions.
Comments
Post a Comment