使用 curl for PHP XML 生成的 HTTP 响应


using curl for php xml generated http response

我有一个错误

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity

我在同一台服务器上有两个PHP文件,并希望从生成XML的PHP接收HTTP响应

更新.php

<?php
$url = '[pathtofile]response.php';
$ch = curl_init($url);
curl_setopt($ch,  CURLOPT_RETURNTRANSFER, TRUE);
/* Get the HTML or whatever is linked in $url. */
$response = curl_exec($ch);
$xml = simplexml_load_file($response);
curl_close($ch);
?>

和响应.php

<?php
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='ISO-8859-1'?>";
echo "<note>";
echo "<from>Jani</from>";
echo "<to>Tove</to>";
echo "<message>Remember me this weekend</message>";
echo "</note>";
?>

导致错误的原因是什么?

使用此示例:

<?php
function download_page($path){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$path);
    curl_setopt($ch, CURLOPT_FAILONERROR,1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    $retValue = curl_exec($ch);          
    curl_close($ch);
    return $retValue;
}
$sXML = download_page('http://alanstorm.com/atom');
$oXML = new SimpleXMLElement($sXML);
foreach($oXML->entry as $oEntry){
    echo $oEntry->title . "'n";
}