这个脚本是我管理过的最好的脚本,它包装了命令行stat
BSD 上提供了一个工具来得出 inode 出生时间属性。
// stat.php
$filename = 'test';
$stat = stat($filename);
date_default_timezone_set('America/Denver');
echo strftime("atime: %H:%M:%S\n", $stat['atime']);
echo strftime("mtime: %H:%M:%S\n", $stat['mtime']);
echo strftime("ctime: %H:%M:%S\n", $stat['ctime']);
if ($handle = popen('stat -f %B ' . escapeshellarg($filename), 'r')) {
$btime = trim(fread($handle, 100));
echo strftime("btime: %H:%M:%S\n", $btime);
pclose($handle);
}
命令行stat
该工具读取 atime、ctime、mtime 的方式与 PHP 的 stat 完全相同,但提供了第四个“inode 诞生时间”参数。 BSDstat()
系统调用在可用时返回 st_birthtime,但我还没有找到一种方法将其本地公开给 PHP。
$ touch test # create a file
$ stat test
..."May 30 06:16:22 2011" "May 30 06:16:22 2011" "May 30 06:16:22 2011" "May 30 06:16:11 2011"...
$ open .
$ touch test # about one minute later
$ stat test
..."May 30 06:17:04 2011" "May 30 06:17:04 2011" "May 30 06:17:04 2011" "May 30 06:16:11 2011"...
$ php stat.php
atime: 06:52:48
mtime: 06:17:04
ctime: 06:17:04
btime: 06:16:11
以下命令返回 unix 时间戳onlyinode 出生时间,这是迄今为止我发现的最好的。你可以运行它popen() http://php.net/manual/en/function.popen.php or proc_open() http://php.net/manual/en/function.proc-open.php
$ stat -f %B test
1306757771