douxia1988 2014-05-04 22:39
浏览 43
已采纳

根据本地文件时差在php中获取rss,而不是cron job

I am on a php script to fetch a local copy of remote rss (xml) file and already I know, I can do it, using a cron job like this
but I think I can do it so far easier using lines of php, to compare server time with the local copied file's timestamp, when calling the php fetch script. if the time is over a threshold like 1hr, I will simply refetch the remote xml, else, process the local xml copy.

Does this approach have any drawbacks?

  • 写回答

1条回答 默认 最新

  • dongnigeng1295 2014-06-11 17:06
    关注

    Take a look at RFC 2616 - Caching in HTTP.

    You even don't need to download file and check the Modified Time.

    You can easily send a request with HEAD method. (not POST or GET) then check some HTTP Response headers like:

    1. Etag

      You can save ETag for each entity and save it somewhere in your server. Then check if ETag has changed, send a GET request to retrieve new file.

    2. Last-Modified

      Using This field is much easier. Compare your last update time with this field's value

    3. Expires

      You can plan to send request in future by this time.

    Existence of each field depends on the webserver's configuration and the way they made RSS Generator. But usually one of these fields exists.

    Also there is alternative way to check content's length by checking the Content-Length field with your file's length which exists on your server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效