在新浪云服务器部署后台,PHP读取XML获取内容。
每刷新十来次就会出现一次无法读取XML的问题。
而在本地部署却没有失败的情况。
解决方法:
不要直接load XML文件,而是先通过file_get_contents读取。
simplexml
<span style="font-size:14px;">$xml="";
$xmlStr = file_get_contents('city_index.xml');
$xml=simplexml_load_string($xmlStr);
//$xml=simplexml_load_file('city_index.xml');</span>
DOM
<span style="font-size:14px;">$dom = new DOMDocument();
$xmlStr = file_get_contents('city_index.xml');
$dom->loadXML($xmlStr);
//$dom->load('city_index.xml');</span>