Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top