开发者

php library for caching of downloads

is there a php library that implements caching for http downloads?

When downloading a document via http with the library, I would expect it to keep a copy of the document locally, and return the local copy at each subsequent call (for the same ur开发者_开发知识库l) except if the remote file has changed. The library would use http headers to find out when the file has changed last.

Alternatively. Any suggestions how this could be implemented with a few lines of code?

thanks

Kurt


You can use curl, and look for the 304 Not Modified status header. Any cache to file, you would need to specify yourself (e.g where to store the file etc.)

// Document unmodified? Return the cache file
if ($cache_exists && ($status == 304)) {
  return file_get_contents($cache_file);
}

A quick google search for it gave me the following hit: http://www.lazycat.org/php-curl.php which appear to contain a working example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜