RE: [PHP] Poor man's cache...
| From: | Maxim Maletsky \(PHPBeginner.com\) | Date: | Fri, 28 Sep 2001 01:37:32 +0000 |
| Subject: | RE: [PHP] Poor man's cache... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-69087@lists.php.net to get a copy of this message | ||
You could invent your own with apache's mod_rewrite. Check for the page
if exists, if it does load it, if it doesn't load another page which in
this case would be your own 404 handler with "normal" headers. I used
this on a relatively heavy site, except the fact that mod_rewrite was
already a need and so the error handling this way was simply an easier
solution. If you do not use mod_rewrite than it might be an extra load,
though.
Maxim Maletsky
www.PHPBeginner.com
-----Original Message-----
From: Chris Lee [mailto:lee@mediawaveonline.com]
Sent: giovedì 27 settembre 2001 21.52
To: php-general@lists.php.net
Subject: Re: [PHP] Poor man's cache...
I had problems with using a 404 document, the 404 headers were still
being sent, the 404.php file would pickup and send the correct data, but
the headers still contained a 404 error, this was causing strange errors
in some browsers having the 404.php file output images, more of a
problem was having the 404.php doc output a file for download, the 404
error was messing things up. I dont know how to change it so the 404
header doesnt get sent.
--
Chris Lee
lee@mediawaveonline.com
"Rasmus Lerdorf" <rasmus@php.net> wrote in message
news:Pine.LNX.4.33.0109271153440.1491-100000@master.php.net...
> Instead of the redirect like that, you could set up an ErrorDocument
> 404 handler in your httpd.conf and in that handler script check for
> that specific URL and generate it. If the file exists your 404
> handler won't get called and you save yourself a stat() and a
> redirect.
>
> The other way is to stick a reverse-proxy like Squid in front of your
> server and send an appropriate Cache-Control header from your script.
> Or even a combination of both.
>
> -Rasmus
>
> On Thu, 27 Sep 2001, Chris Hobbs wrote:
>
> > Well, I built a really awful Table of Contents script yesterday that
> > has to grep through about a thousand files (Word docs, no less) to
> > find the titles. Anyway, the script works great, but it is slow -
> > 20-30 seconds per load, which is hardly acceptable. So, since the
> > data will only change occasionally, I wrote the following wrapper
> > for the script to check if a cachefile already exists, and if it
> > does, it redirects to it. If not, it uses php's output buffering to
> > build the page, writes the buffer out to the cache file, and then
> > dumps the buffer to the browser.
> >
> > When I change the docs on the site, I merely have to delete the
> > cached file - the next person that loads it will rebuild it for me.
> >
> > Anyway, I include it here for your edification.
> >
> > <?
> > // Get just the script name, no /'s
> > ereg(".*/(.*)", $PHP_SELF, $regs);
> > $cachefilename = $regs[1].".html";
> > if (file_exists("/path/to/your/cache/$cachefilename")) {
> > header ("Location: $cachefilename");
> > exit ();
> > }
> > ob_start();
> >
> > // All of your normal script goes here, complete with
> > // echo's, pure HTML between ?> and <?, whatever...
> >
> > $complete_page=ob_get_contents();
> > $fd = fopen ("/path/to/your/cache/$cachefilename", "w"); fwrite
> > ($fd, $complete_page); fclose($fd);
> > ob_end_flush();
> > ?>
> >
> > Hope you find it useful!
> >
> >
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net To
contact the list administrators, e-mail: php-list-admin@lists.php.net