A better explanation:
For file $file and UNIX time stored in vars $access and $modified
- change only access time
\touch($file, \filemtime($file), $access);
- change only modified time
\touch($file, $modified, \fileatime($file));
- change both access and modified time
\touch($file, $modified, $access);
Seeing the results:
//use a session cookie stored in a custom folder
$file = '/var/www/test_com/session/sess_qfn587cudfpgsijm1bs4d81s75';
echo 'stats for sess_qfn587cudfpgsijm1bs4d81s75<br/>';
\clearstatcache();
echo 'access: '.\date("Y-m-d H:i:s", \fileatime($file)).'<br/>';
echo 'modified: '.\date("Y-m-d H:i:s", \filemtime($file)).'<br/>';
echo 'change access to now, modified +1 hour<br/>';
\touch($x, \filemtime($file)+3600, time());
\clearstatcache();
echo 'access: '.\date("Y-m-d H:i:s", \fileatime($file)).'<br/>';
echo 'modified: '.\date("Y-m-d H:i:s", \filemtime($file)).'<br/>';
Notice the double call to clearstatcache()!