【问题标题】:Reading an URL with fopen + fgetcsv: does it use a cache?使用 fopen + fgetcsv 读取 URL:它使用缓存吗?
【发布时间】:2019-10-31 21:52:34
【问题描述】:

我有一个在线 CSV,有时会更新。我打开并阅读它:

$f = fopen("http://www.example.com/myfile.csv", "r"); 
$headers = fgetcsv($f); 
while ($row = fgetcsv($f)) 
{
    echo $row[0];
}
fclose($f);

有时我注意到以下问题:我知道在线 CSV 已更新,但似乎此 PHP 代码读取的是旧版本的 CSV(之前通过调用相同的 PHP 代码),就像它使用 myfile.csv 的缓存版本一样。

fopen($url, "r") 的缓存设置在哪里?有没有办法强制重新下载 URL 并绕过任何缓存系统?

PS:在内部,fopen 使用什么来打开非文件系统文件但远程文件/互联网 URL?

【问题讨论】:

标签: php caching fopen fgetcsv


【解决方案1】:

事实上fopen 似乎不受缓存的影响,文档https://www.php.net/manual/en/function.clearstatcache.php 指出:

受影响的函数包括 stat()、lstat()、file_exists()、is_writable()、is_readable()、is_executable()、is_file()、is_dir()、is_link()、filectime()、fileatime()、 filemtime()、fileinode()、filegroup()、fileowner()、filesize()、filetype() 和 fileperms()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多