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 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划