Skip to content

Instantly share code, notes, and snippets.

@PeterJCLaw
Created January 14, 2012 22:56
Show Gist options
  • Select an option

  • Save PeterJCLaw/1613263 to your computer and use it in GitHub Desktop.

Select an option

Save PeterJCLaw/1613263 to your computer and use it in GitHub Desktop.
Testing PHP's touch and fileXtime functions
<?php
$file = 'bacon';
$dateFormat = 'F d Y H:i:s.u';
unlink($file);
var_dump(file_put_contents($file, rand()));
echo 'atime: '; var_dump(date($dateFormat, fileatime($file)));
echo 'ctime: '; var_dump(date($dateFormat, filectime($file)));
echo 'mtime: '; var_dump(date($dateFormat, filemtime($file)));
$touchTime = mktime(1,1,1);
echo 'touch Time: ', date($dateFormat, $touchTime), PHP_EOL;
var_dump(touch($file, $touchTime));
sleep(1);
echo 'atime: '; var_dump(date($dateFormat, fileatime($file)));
echo 'ctime: '; var_dump(date($dateFormat, filectime($file)));
echo 'mtime: '; var_dump(date($dateFormat, filemtime($file)));
//*/
int(9)
atime: string(31) "January 14 2012 22:57:01.000000"
ctime: string(31) "January 14 2012 22:57:01.000000"
mtime: string(31) "January 14 2012 22:57:01.000000"
touch Time: January 14 2012 01:01:01.000000
bool(true)
atime: string(31) "January 14 2012 22:57:01.000000"
ctime: string(31) "January 14 2012 22:57:01.000000"
mtime: string(31) "January 14 2012 22:57:01.000000"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment