filemtime
filemtime is a PHP function that returns the Unix timestamp indicating the last modification time of a file or directory. It is part of PHP’s standard library and relies on the system's file metadata to report when the file’s content was last changed.
- int|false filemtime(string $filename)
- Returns the integer Unix timestamp of the last modification time on success, or false on failure.
- The function follows symbolic links, meaning the timestamp corresponds to the target file’s modification time. If
- The timestamp is suitable for time-based logic, such as cache invalidation or monitoring changes to a
- The filename parameter can be a path to a local file or a stream-wrapped resource that PHP
- echo date("Y-m-d H:i:s", filemtime("path/to/file.txt"));
- if (filemtime("path/to/file.txt") > time() - 3600) { /* recent change within last hour */ }
- filemtime is often used alongside file_exists, fileatime (access time), and filectime (inode change time) to build
This function is commonly employed for cache management, auto-rebuild triggers, and scripts that react to file