PHP | fileatime( ) Function
Last Updated :
03 May, 2018
Improve
The fileatime() function in PHP is an inbuilt function which is used to return the last access time of a specified file. The fileatime() function returns the last access time of a file as a Unix Timestamp on success and False on failure.
The filename is passed as a parameter to the fileatime() function. The result of the fileatime() function is cached and a function called clearstatcache() is used to clear the cache.
Syntax:
php
Output:
php
Output:
fileatime($filename)Parameters: The fileatime() function in PHP accepts only one parameter $filename. It specifies the file whose last access time you want to check. Return Value: It returns the last access time of a file as a Unix Timestamp on success and False on failure. Errors And Exception:
- The time resolution may differ from one file system to another.
- This function doesn't works on some unix systems which have access time updates are disabled to increase performance.
Input : echo fileatime("gfg.txt"); Output : 1525159574 Input : echo "Last accessed: ".date("F d Y H:i:s.", fileatime("gfg.txt")); Output : Last accessed: May 1 2018 07:26:14.Below programs illustrate the fileatime() function. Program 1:
<?php
// checking last accessed time of a file
echo fileatime("gfg.txt");
?>
1525159574Program 2:
<?php
// checking last accessed time of a file
echo fileatime("gfg.txt");
//checking last accessed time of a file
// and formatting the output of the date
echo "Last accessed: ".date("F d Y H:i:s.",
fileatime("gfg.txt"));
?>
1525159574 Last accessed: May 1 2018 07:26:14.Reference: http://php.net/manual/en/function.fileatime.php