dqkxo44488 2013-11-10 08:53
浏览 66
已采纳

自上次下载以来,上次修改以检查订阅源已更新

i am using PHP to read feed xml in every half an hour, as of now i am always reading whole feed file whether it is updated or not. But i want to check whether feed xml is update since last download, if updated then only read the xml otherwise not.

I am trying to achieve it using below code, but $lastmodifiedRSS is always empty. I am not sure what is going wrong in my code. If i get $lastmodifiedRSS then i can easily compare it with last loaded time and then decide what to do.

If any Expert can share some info that would be great. Thank you in advance.

//get feed information & content
$feed = new feed($rssurl);
$feed->load();

//get the last modified date (web server information)
$lastmodifiedRSS = $feed->http->get_header_value('Last-Modified');

        function http($url)
{
    $this->url($url);
    $this->user_agent = 'posh';
    $this->header = "";
    $this->code = "";
    $this->codeStr = "";
    $this->max_d = 5;
    $this->authorization = "";
    $this->proxy_auth = "";
    $this->url = $url;
    $this->addProxy();
}

    function feed($url)
{
    if ($url) {
        $this->url = $url;
        $this->http = new http($url);
        //$this->addProxy();
    } else {
        $this->http = new http('');      
    }
}
function load()
    {
        $content= $this->http->get();
        if (!$content)
            return false;
        $content = $this->transcode($content);
        return $content;
    }

function get_header_value($name)
    {
        if (preg_match("/$name: ?([^\\
]*)\\
/m",$this->head,$matches) !== false)
        {
            if (count($matches) > 1)
            {
                return $matches[1];
            }
        }
        return false;
    }

Regards, Mona

  • 写回答

2条回答 默认 最新

  • dsfgdsjfd78773 2013-11-10 09:04
    关注

    Make use of stat() in PHP

    <?php
    print_r(stat('users.json'));
    

    OUTPUT:

    Array ( [0] => 2 [1] => 0 [2] => 33206 [3] => 1 [4] => 0 [5] => 0 [6] => 2 [7] => 298 [8] => 1384073940 [9] => 1384073940 [10] => 1368626190 [11] => -1 [12] => -1 [dev] => 2 [ino] => 0 [mode] => 33206 [nlink] => 1 [uid] => 0 [gid] => 0 [rdev] => 2 [size] => 298 [atime] => 1384073940 [mtime] => 1384073940 [ctime] => 1368626190 [blksize] => -1 [blocks] => -1 )
    

    Source

    Keeping a track of the variables [atime] , [size] can help you achieve what you are trying to do.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看