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.

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?