trying to read live rss, but its returning same xml

邮差的信 提交于 2019-12-10 10:54:07

问题


I am trying to read xml file from "http://synd.cricbuzz.com/score-gadget/gadget-scores-feed.xml" I understand its caching issue so i have added no-cache but stil its returning same file :(

<?php 
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Pragma: no-cache"); Header('Pragma: no-cache');

    $url = "http://synd.cricbuzz.com/score-gadget/gadget-scores-feed.xml";

    $curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $result = curl_exec ($curl);
    curl_close ($curl);
    print $result;
    $fp = fopen('score.xml', 'w');
    if($fp)
        fwrite($fp,  $result);  
    else
    echo "Error !";

    $url = "score.xml";
    $xml = simplexml_load_file($url);

    var_dump($xml);
 ?>

回答1:


Try setting the following options to prevent caching :

curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); 
curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); 

Docs on curl_setopt here



来源:https://stackoverflow.com/questions/8740521/trying-to-read-live-rss-but-its-returning-same-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!