Example 1 — Read the Access Time
Set a known access time with touch() and read it back with fileatime().
<?php
$path = sys_get_temp_dir() . '/codetofun_fileatime.txt';
file_put_contents($path, 'Hello');
touch($path, 1700000000, 1700000000);
clearstatcache();
$accessed = fileatime($path);
echo 'Timestamp: ', $accessed, PHP_EOL;
echo 'Date (UTC): ', gmdate('Y-m-d H:i:s', $accessed), PHP_EOL;
unlink($path); How It Works
- file_put_contents() creates a small demo file.
- touch() sets both the modification time and the access time to 1700000000.
- clearstatcache() clears PHP's cached file information so the new value is read.
- gmdate() turns the timestamp into a readable UTC date.

