note 74032 added to ref.apc
| From: | ashus at atlas dot cz | Date: | Wed, 21 Mar 2007 14:56:47 +0000 |
| Subject: | note 74032 added to ref.apc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124670@lists.php.net to get a copy of this message | ||
If you don't really need caching and plan to use it for one page only, you could try an
alternative; writing a file and then flushing it back if specified time hasn't passed. I use it
to read and parse third party websites, to check for new subtitles and output a RSS xml file.
<?php
if ((is_file($_SERVER['SCRIPT_FILENAME'].'.cached'))
&& (time()-filemtime($_SERVER['SCRIPT_FILENAME'].'.cached') < 3600))
{
readfile($_SERVER['SCRIPT_FILENAME'].'.cached');
exit;
}
// (the php script itself goes here)
echo $out;
$fp = fopen($_SERVER['SCRIPT_FILENAME'].'.cached', 'w');
fwrite($fp, $out);
fclose($fp);
?>
Note, that this only works for pages, which are without GET or POST variables, sessions, etc. You
can change the number of seconds the cache works for (3600 = an hour). Also, use "$out.="
instead of "echo" command. Just store all output to that variable (if you need to use it
inside a function, use "global $out" instead).
This workaround was written in about 5 minutes and may contain bugs.
----
Server IP: 212.24.129.110
Probable Submitter: 85.135.10.2 (proxied: 10.152.66.26, 10.152.42.19)
----
Manual Page -- http://www.php.net/manual/en/ref.apc.php
Edit -- https://master.php.net/note/edit/74032
Del: integrated -- https://master.php.net/note/delete/74032/integrated
Del: useless -- https://master.php.net/note/delete/74032/useless
Del: bad code -- https://master.php.net/note/delete/74032/bad+code
Del: spam -- https://master.php.net/note/delete/74032/spam
Del: non-english -- https://master.php.net/note/delete/74032/non-english
Del: in docs -- https://master.php.net/note/delete/74032/in+docs
Del: other reasons-- https://master.php.net/note/delete/74032
Reject -- https://master.php.net/note/reject/74032
Search -- https://master.php.net/manage/user-notes.php