If the file system is ext4 (common for later unixes / linux, such as Ubuntu) or ntfs (Windows), then mtime has subnet precision.
If the ext3 file system (or perhaps others, it was the standard time ago and is still used by RHEL), then mtime only saved in the next second. Perhaps the old default option is that PHP only supports mtime until the next second.
To get the value in PHP, you need to call an external utility, since PHP itself does not support it.
(I tested the following only on a system with English, the "custom" stat output may be different, or strtotime behavior may be different in non-English languages. It should work fine in any time zone, since the stat output includes the time zone specifier that strtotime adheres strtotime .)
class FileModTimeHelper { public static function getFileModMicrotime($filename) { $stat = `stat --format=%y $filename`; $patt = '/^(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d)\.(\d+) (.*)$/'; if (!preg_match($patt, $stat, $matches)) { throw new \Exception("Unrecognised output from stat. Expecting something like '$patt', found: '$stat'"); } $mtimeSeconds = strtotime("{$matches[1]} {$matches[3]}"); $mtimeMillis = $matches[2]; return "$mtimeSeconds.$mtimeMillis"; } }
Rich
source share