试图读取实时rss,但它返回相同的xml

时间:2012-01-05 09:55:40

标签: php curl simplexml

我正在尝试从“http://synd.cricbuzz.com/score-gadget/gadget-scores-feed.xml”中读取xml文件我理解它的缓存问题,所以我添加了no-cache但stil返回同一档案:(

<?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 个答案:

答案 0 :(得分:1)

尝试设置以下选项以防止缓存:

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

Docs on curl_setopt here