Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP fileatime() Function.
The built-in PHP fileatime() function returns the last access time of the specified file.
The built-in PHP fileatime() function returns the last access time of the specified file.
Syntax
Following below is the syntax to use this function -
int fileatime ( string $filename )
READ: PHP | file() Function
Note: The result of this function has being cached. We can use the clearstatcache() function to clear the cache.
The access time of the file can be changed whenever the data block in the file is read. Systems running on Unix operating system turn off access time update because when an application frequently accesses a large number of files, it can affect performance. So turning off access time update improves the performance of such applications.
The access time of the file can be changed whenever the data block in the file is read. Systems running on Unix operating system turn off access time update because when an application frequently accesses a large number of files, it can affect performance. So turning off access time update improves the performance of such applications.
Return Value
This function returns the last access time as Unix timestamp on success, or false on failure.
Example1
Try out the below example -
<?php echo fileatime("/PhpProject/sample.txt"); echo "\n"; echo "Last access: ".date("F d Y H:i:s.",fileatime("/PhpProject/sample.txt")); ?>
Output
When the above code is executed, it will produce the following result -
1590217956 Last access: May 23 2020 09:12:36.
Example2
Try out the below example -
<?php $filename = "/PhpProject/sample.txt"; if(file_exists($filename)) { echo "$filename was last accessed at: " . date("F d Y H:i:s.", fileatime($filename)); } ?>
Output
When the above code is executed, it will produce the following result -
/PhpProject/sample.txt was last accessed at: May 23 2020 09:12:36.
Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial guide, we are going to be discussing about the PHP filectime() Function.
Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.
Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.