php - 文件修改时间的filectime vs filemtime?

标签 php caching

我试图确保某些图像在修改时不会被缓存,但哪些图像更适合此 filectimefilemtime

我真的看不出与 php 手册有什么不同?会更快吗?

<img src="/images/123.png?<?=md5(@filectime("/images/123.png"))?>" />
<img src="/images/123.png?<?=md5(@filemtime("/images/123.png"))?>" />

还有像这样的函数不会发出 e_warning 吗?关于文件错误?

理想情况下,我不想只提供问号 <img src="/images/123.png?" />

最佳答案

当你处理图像缓存时,filectime 是不合适的 - 它标志着最后一次:

when the permissions, owner, group, or other metadata from the inode is updated

您想知道图像文件内容是否已更改 - 是否已调整大小、裁剪或完全替换。

因此,filemtime更适合你的应用:

when the data blocks of a file were being written to, that is, the time when the content of the file was changed

如果您不希望 ? 一直出现,请先将 filemtime 设置为一个变量并对其进行测试:

$filemtime = @filemtime("/images/123.png");

<img src="/images/123.png<?= $filemtime ? '?' . $filemtime : ''?>" />

更好的是,在使用 filemtime 之前使用 file_exists() 测试文件是否存在。

关于php - 文件修改时间的filectime vs filemtime?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22042611/

相关文章:

php - SQL Where NOT Exists 插入

php - 来自PHP服务器的AngularJS流音频

php - 依赖注入(inject) : should I inject everything or use a service locator for some objects?

c# - 使用集合时如何实现线程安全的缓存机制?

c - C中Cache方法的理解

php - CodeIgniter 和 Smarty

php - 如何获得以像素为单位的固定宽度的完整单词的子字符串

c# - 重定向到页面和按下后退按钮后进入同一页面之间的区别?

javascript - 对话框ajax加载动画效果-需要循环延迟、 sleep

java - 文件存储服务器