This script is the best I have succeeded in wrapping the stat command line tool available in BSD to come up with the inode birth attribute.
// 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); }
The stat command line tool reads atime, ctime, mtime in the same way as PHP stat, but the fourth parameter, "inode time of birth," appears. The BSD stat() system call returns st_birthtime when it is available, but I have not found a way to expose it in 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
The following command returns the unix timestamp of only the inode timestamp, and this is the best I've found so far. You can run it with popen () or proc_open ()
$ stat -f %B test 1306757771
lunixbochs May 30 '11 at 12:26 2011-05-30 12:26
source share