Mercurial > hg > index.fcgi > www > www-1
view myrss/index.php @ 41:5f9bc02e9caf
add datetimestamp and caching
author | paulo |
---|---|
date | Fri, 01 Feb 2013 01:26:07 -0800 |
parents | f93693980ead |
children |
line source
1 <?php
2 umask(0037);
4 $start_time = microtime(true);
6 $cache_fn = "__cache__.html";
7 $cache_life = "1200";
9 $cache_mtime = "0";
10 if (file_exists($cache_fn) && filesize($cache_fn) > 0)
11 $cache_mtime = filemtime($cache_fn);
13 $newbody = '';
15 if ((time() - $cache_mtime >= $cache_life)) {
16 $newbody = shell_exec('./myrss_update.sh 2>&1');
17 file_put_contents($cache_fn, $newbody);
18 } else {
19 $newbody = file_get_contents($cache_fn);
20 }
22 $end_time = microtime(true);
23 $elapsed_time = $end_time - $start_time;
25 $newbody = preg_replace("/<\/BODY>/", "<DIV class=\"debug\">Time elapsed: " . sprintf("%.3f", $elapsed_time) . " seconds.</DIV>\n</BODY>", $newbody);
26 echo $newbody;
27 ?>