Pyh.conf’25: a new PHP conference for the Russian-speaking community

Voting

: five plus one?
(Example: nine)

The Note You're Voting On

erelsgl at gmail dot com
15 years ago
Cheaper and dirtier way to code a cache:

<?php
$cache_file
= 'URI to cache file';
$cache_life = '120'; //caching time, in seconds

$filemtime = @filemtime($cache_file); // returns FALSE if file does not exist
if (!$filemtime or (time() - $filemtime >= $cache_life)){
ob_start();
resource_consuming_function();
file_put_contents($cache_file,ob_get_flush());
}else{
readfile($cache_file);
}
?>

<< Back to user notes page

To Top