Php 上次修改以检查提要自上次下载以来是否已更新

Php 上次修改以检查提要自上次下载以来是否已更新,php,rss-reader,feed,feedparser,Php,Rss Reader,Feed,Feedparser,我使用PHP每半小时读取一次提要xml,到目前为止,无论提要文件是否更新,我都会读取整个提要文件。但我想检查自上次下载以来提要xml是否更新,如果更新了,则只读取xml,否则不读取 我试图用下面的代码实现它,但是$lastmodifiedRSS总是空的。我不确定我的代码出了什么问题。如果我得到$lastmodifiedRSS,那么我可以轻松地将它与上次加载的时间进行比较,然后决定要做什么 如果有专家能分享一些信息那就太好了。先谢谢你 //get feed information & co

我使用PHP每半小时读取一次提要xml,到目前为止,无论提要文件是否更新,我都会读取整个提要文件。但我想检查自上次下载以来提要xml是否更新,如果更新了,则只读取xml,否则不读取

我试图用下面的代码实现它,但是$lastmodifiedRSS总是空的。我不确定我的代码出了什么问题。如果我得到$lastmodifiedRSS,那么我可以轻松地将它与上次加载的时间进行比较,然后决定要做什么

如果有专家能分享一些信息那就太好了。先谢谢你

//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: ?([^\\r\\n]*)\\r\\n/m",$this->head,$matches) !== false)
        {
            if (count($matches) > 1)
            {
                return $matches[1];
            }
        }
        return false;
    }
问候,,
Mona在PHP中使用
stat()

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


跟踪变量[atime]、[size]可以帮助您实现您想要做的事情。使用HTTP头本身可以更好地处理这种检查

如果服务器在响应中发送
Etag
头,您可以在下一个请求中将其与
If None Match
头一起使用,以了解文件是否已更改

类似地,如果服务器在响应中发送
Last Modified
头,您可以在下一个请求中使用
if Modified-Since
头的时间戳来了解文件是否已更改


为了让您知道您可以做什么,我不能提供任何代码,因为我不知道您在这里使用的是哪个HTTP库。

嗨,Shankar,谢谢您的回答。。这是mtime,这将给我饲料文件修改时间…所有的远程文件将它的工作…是的,莫娜,这是正确的。但它返回一个UNIX时间戳。
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 )