問題描述
我正在努力從網絡服務器收集 PHP 腳本的自動數據.相關文件包含氣象數據,每 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.
避免這種情況的一種非常簡單和骯臟的方法是向每個請求附加一些隨機獲取參數.
A very simple and dirty way to avoid that is to append some random get parameter to each request.
這篇關于PHPs fopen 函數是否實現了某種緩存?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!