note 33484 added to function.ob-end-clean
| From: | programmer at bardware dot de | Date: | Fri, 27 Jun 2003 11:32:37 +0000 |
| Subject: | note 33484 added to function.ob-end-clean | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51089@lists.php.net to get a copy of this message | ||
You might want to prevent your script from executing if the client already has the latest version.
You can do it like so:
ob_start();
$mtime=filemtime($_SERVER["SCRIPT_FILENAME"])-date("Z");
$gmt_mtime = date('D, d M Y H:i:s', $mtime) . ' GMT';
$headers = getallheaders();
if(isset($headers["If-Modified-Since"])) {
if ($headers["If-Modified-Since"] == $gmt_mtime) {
header("HTTP/1.1 304 Not Modified");
ob_end_clean();
exit;
}
}
$size=ob_get_length();
header("Last-Modified: ".$gmt_mtime);
header("Content-Length: $size");
ob_end_flush();
Instead of checking the If-Modified-Since-Header against the date of the last modification of the
script, you can of course query a database or take any other date that is somehow related to the
modification of the result of your script.
You can for instance use this technique to generate images dynamically. If the user indicates he
already has a version of the image by the If-Modified-Since-Header, there's no need to generate
it and let the server finally discard it because the server only then interpretes the
If-Modified-Since-Header.
This saves server load and shortens response-times.
----
Manual Page -- http://www.php.net/manual/en/function.ob-end-clean.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33484
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33484&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33484&report=yes