Skip to content

Instantly share code, notes, and snippets.

@snpy
Last active October 4, 2015 23:37
Show Gist options
  • Save snpy/2717130 to your computer and use it in GitHub Desktop.
Save snpy/2717130 to your computer and use it in GitHub Desktop.
Real time web resource salt vs predefined (i.e. constant)
<?php
$mt = microtime(1);
for ($i = 0; $i < 10000; ++$i) {
clearstatcache();
$file = 'file-prefix.' . date('Ymdh', filemtime('some-file.txt')) . '.txt';
}
echo microtime(1) - $mt, PHP_EOL, $file, PHP_EOL;
<?php
$mt = microtime(1);
define('WEB_RESOURCES_SALT', '2012051505');
for ($i = 0; $i < 10000; ++$i) {
$file = 'file-prefix.' . WEB_RESOURCES_SALT . '.txt';
}
echo microtime(1) - $mt, PHP_EOL, $file, PHP_EOL;
/* nothing here; file required by filemtime-clearstatscache.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment