简体   繁体   English

filectime 与 filemtime 的文件修改时间?

[英]filectime vs filemtime for file modification time?

I'm trying to ensure some images aren't cached when they're modified but which would be more suitable for this filectime or filemtime ?我想,以确保某些图像不会被缓存时,他们正在修改,但是这将是更适合这个filectimefilemtime

I can't really see much difference from the php manuals?我真的看不出与 php 手册有多大区别? Would either be faster?要么更快?

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

Also is there a function like this that doesn't emit an e_warning on file error?还有这样的函数不会在文件错误时发出e_warning吗?

Ideally I don't want to ever serve just the question mark <img src="/images/123.png?" />理想情况下,我不想只提供问号<img src="/images/123.png?" /> <img src="/images/123.png?" />

As you're dealing with image caching, filectime is inappropriate - it marks the last time:当您处理图像缓存时, filectime是不合适的 - 它标志着最后一次:

when the permissions, owner, group, or other metadata from the inode is updated当来自 inode 的权限、所有者、组或其他元数据更新时

You want to know if the image file content has changed - if it's been resized, cropped or replaced entirely.您想知道图像文件内容是否已更改 - 是否已调整大小、裁剪或完全替换。

Therefore, filemtime is more suitable for your application:因此, filemtime更适合您的应用:

when the data blocks of a file were being written to, that is, the time when the content of the file was changed当文件的数据块被写入时,即文件内容被改变的时间

If you don't want the ?如果你不想要? to always appear, set filemtime to a variable first and test for it:要始终出现, filemtimefilemtime设置为变量并对其进行测试:

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

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

Better still, test for the existence of the file with file_exists() before using filemtime .更好的是,在使用filemtime之前使用file_exists()测试文件是否存在。

Note: In most Unix filesystems, a file is considered changed when its inode data is changed;注意:在大多数 Unix 文件系统中,当文件的 inode 数据发生变化时,就认为文件发生了变化; that is, when the permissions, owner, group, or other metadata from the inode is updated.也就是说,当来自 inode 的权限、所有者、组或其他元数据更新时。 See also filemtime() (which is what you want to use when you want to create "Last Modified" footers on web pages) and fileatime().另请参见 filemtime()(当您想在网页上创建“上次修改”页脚时要使用它)和 fileatime()。

From the manual手册

So you want to use filemtime .所以你想使用filemtime

filemtime: Represents when the data or content is changed or modified, not including that of meta data such as ownership or ownergroup. filemtime:表示数据或内容发生变化或修改的时间,不包括所有权或所有者组等元数据。

filectime: Represents the time when the meta data or inode data of a file is altered, such as the change of permissions, ownership or group. filectime:表示文件的元数据或inode数据发生改变的时间,例如权限、所有权或组的改变。

so filemtime is the solution.所以filemtime是解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM