PHP Function Reference

PHP fileatime() Function



The PHP fileatime() function returns the last access time of the specified file.

Note: The results of this function are cached. Use clearstatcache() function to clear the cache.

Note: The atime of a file is supposed to change whenever the data blocks of a file are being read. This can decrease the performance if an application accesses a large number of files or directories. Some Unix systems have access time updates disabled to increase performance. On such filesystems this function will be useless.

Syntax

fileatime(filename)

Parameters

filename Required. Specify the path to the file to check.

Return Value

Returns the time the file was last accessed, or false on failure. The time is returned as a Unix timestamp, which is suitable for the date() function.

Exceptions

Upon failure, an E_WARNING is thrown.

Example:

Lets assume that we have a file called test.txt in the current working directory. The example below demonstrates on using this function to get the time when this file was last accessed.

<?php
$filename = 'test.txt';

//getting the time when $filename 
//was last accessed
if (file_exists($filename)) {
  echo "$filename was last accessed: "
       .date("F d Y H:i:s.", fileatime($filename));
} else {
  echo "$filename is not found.";
}
?>

The output of the above code will be:

test.txt was last accessed: September 01 2021 14:41:34.

❮ PHP Filesystem Reference