I am trying to make my php-generated images cache. Here is a summary of the script with the headers. It doesn't seem to cache though. Do I need to do something special to make sure it caches? -
//summarised
-
-
//resize...
-
$file= $_GET['file'];
-
$o= imagecreatefromgif($file);
-
$i= imagecreatetruecolor($w,$h);
-
imagecopyresampled($i,$o,0,0,0,0,$w,$h,$wo,$ho);
-
-
//output
-
header('Content-type: image/gif');
-
header('Expires: '.date(DATE_RFC1123,time()+2592000));
-
imagegif($i);
-
imagedestroy($i);
-
-
Here are the response headers (using firebug). The server clearly gets the expires header. But I still have the overhead showing in firebug.
Date Tue, 29 Jul 2008 13:06:36 GMT
Server Apache/2.0.55 (Ubuntu) PHP/5.1.2
X-Powered-By PHP/5.1.2
Expires Thu, 28 Aug 2008 14:06:36 BST
Content-Length 2182
Keep-Alive timeout=15, max=95
Connection Keep-Alive
Content-Type image/gif
2 5102
Heya, Henry.
I hate to just drop an article on you, but I have to run out the door in a sec. In the meantime, perhaps this article will have some information that you might find useful ( http://www.mnot.net/cache_docs/).
And I am now subscribed to this thread (:
I hate to just drop an article on you,
That's fine! I'd seen this one but it seems like it was one of those occasions where I just didn't type the right thing into google yesterday!
I just found this: http://php.dtbaker.com.au/post/cachi..._php_imagejpeg
The solution is to use the last-modified header based on the filemtime() for the input file. The article has a solution if you have no input file too. The browser now caches the images. I hope it will refresh when they are updated! -
//summarised
-
//two additions - check last-modified header and exit if same as
-
//filemtime(), also set last-modified header
-
-
//resize...
-
$file= $_GET['file'];
-
-
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])==filemtime($file)) {
-
header('Last-modified: '.date(DATERFC_1123,filemtime($file)),true,304);
-
exit;
-
}
-
-
$o= imagecreatefromgif($file);
-
$i= imagecreatetruecolor($w,$h);
-
imagecopyresampled($i,$o,0,0,0,0,$w,$h,$wo,$ho);
-
-
//output
-
header('Content-type: image/gif');
-
header('Expires: '.date(DATE_RFC1123,time()+2592000));
-
header('Last-modified: '.date(DATE_RFC1123,filemtime($file);
-
imagegif($i);
-
imagedestroy($i);
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: sunil |
last post by:
Iam trying to implement sorting.
I know how to display a button in the header of an datagrid. How can i
display an image with down arrow and uparrow along the side of button on the
header.
Any...
|
by: Olav Tollefsen |
last post by:
I have som code that dynamically generates an image and writes it back to
the browser from an .aspx codebehind file like this:
System.Drawing.Image image;
image = GenerateImage();...
|
by: eff_kay |
last post by:
How can I use an image as background image for header of a datagrid
Stuck!!!!!
eff_kay
|
by: Les Caudle |
last post by:
Anyone have some sample code for a database generated menu based on a DataList
(or other control). that would also generate the javascript necessary for a
rollover to a 2nd image when the mouse...
|
by: Ersin Gençtürk |
last post by:
Hi ,
I am creating dynamic images (for example writing text into a bitmap) and
saving it to the output stream with gdi library in .net but I can't adjust
image quality.
The best parameters...
|
by: VP |
last post by:
I would like to specify 'Expires' header for a js file. Can you please let
me know where & how to specify that.
Thanks.
|
by: dave Cheseldine |
last post by:
Hi
I want to stop a gd generated image from being cached.
It is called into index.php file as follows:
<image src =
"http://www.daveches.co.uk/importimage/importimage.php?x=$randomNumber"...
|
by: Jim Michaels |
last post by:
<?php
include 'dbinc.php';
$result = mysql_query("SELECT image,mime_type FROM photos WHERE
image_id=".intval($_GET), $link) or die("MyErr:".mysql_error());
if ($row = mysql_fetch_assoc($result))...
|
by: helveticus |
last post by:
I'm having difficulties setting the expires header for images and css
files in my compression HttpModule. Compression is carried out by
context_BeginRequest and works fine (code not shown)....
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |