PHPs fopen函数是否实现了某种缓存? [英] Does PHPs fopen function implement some kind of cache?
问题描述
我正在努力从网络服务器上自动收集PHP脚本数据。 相关文件包含meteo数据,每10分钟更新一次。奇怪的是,网络服务器上的'文件修改'日期不会改变。
I'm struggling with the automated data collection of a PHP script from a webserver. The files in question contain meteo data and are updated every 10 minutes. Weirdly enough, the 'file modified' date on the webserver doesn't change.
一个简单的 fopen ('http:// ...') - 命令尝试每小时获取此目录中最后一个文件的最新版本。但经常我最终得到一个长达4个小时的版本。这发生在Linux服务器上(正如我的系统管理员向我保证的那样)不使用任何类型的代理服务器。
A simple fopen('http://...')-command tries to get the freshest version of the last file in this directory every hour. But regularly I end up with a version up to 4 hours old. This happens on a Linux server which (As my system administrator has assured me) doesn't use a proxy server of any kind.
PHP是否实现了自己的缓存机制?或者还有什么可能干扰这里?
Does PHP implement its own caching mechanism? Or what else could be interfering here?
(我目前的解决方法是通过exec('wget --nocache ...')获取文件,这有效。)
(My current workaround is to grab the file via exec('wget --nocache...') which works.)
推荐答案
由于您是通过HTTP获取文件,我假设PHP将遵循服务器响应的任何缓存头使用。
Since you're getting the file via HTTP, I'm assuming that PHP will be honouring any cache headers the server is responding with.
一种非常简单和肮脏的方法是为每个请求添加一些随机get参数。
A very simple and dirty way to avoid that is to append some random get parameter to each request.
这篇关于PHPs fopen函数是否实现了某种缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!