PHP image generation & caching

This is a discussion on PHP image generation & caching within the PHP Language forums, part of the PHP Programming Forums category; Hello, I hope you can help - I'm a bit new to PHP. My basic problem is with a page (...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-13-2004
Mr WZ Boson
 
Posts: n/a
Default PHP image generation & caching

Hello,

I hope you can help - I'm a bit new to PHP.

My basic problem is with a page (HTML) which is intended to display an
image slideshow. On this page there are a number of links to click
(one for each slideshow topic) and a "TV screen" to view the results.

The images are stored on the server as (big) JPG files - and when they
are downloaded for the slideshow, I resize them with a PHP script
"im.php" :

$filename = $_GET['filename'];
header('Content-type: image/jpeg');
..
..... open $filename & do the resizing
..
imagejpeg( ...


After a link is selected, I preload the set of images with Javascript
by doing :

im[i].src = "php/im.php?filename=" + getFName(i); // for each in the
set

where getFname(i) returns the i'th image in the set.

I then start the slideshow (I've got things in the Javascript to make
sure all images are preloaded before starting)

Now, my problem is that the browser doesn't seem to be caching the
images and keeps making server requests during the slidehow (which
rather defeats the idea of pre-loading)

If I "cheat" and replace the preloading with :

im[i] = getFName(i);

it works fine (i.e I can switch the server off & it continues to show
the slideshow).

This happens with all browsers I've tried (IE6, Firefox, Netscape)

Hope all this makes sense & would appreciate your expert advice.

Mr WZ Boson
Reply With Quote
  #2 (permalink)  
Old 12-14-2004
Daniel Tryba
 
Posts: n/a
Default Re: PHP image generation & caching

Mr WZ Boson <WZ_Boson@yahoo.co.uk> wrote:
> This happens with all browsers I've tried (IE6, Firefox, Netscape)
>
> Hope all this makes sense & would appreciate your expert advice.


Get a packetsniffer (like ethereal) and study the differences in request
and response headers. Also a working example would be nice so "we" will
not have to code (and maybe do something completly different) to see
what you are actually talking about.
Reply With Quote
  #3 (permalink)  
Old 12-14-2004
cyberhorse
 
Posts: n/a
Default Re: PHP image generation & caching

I would also guess that browsers by now have learned not to cache
dynamic pages and when they see im.php?something they will either
detect it as dynamic page or as unknown file type and not cache it
perhaps. When you put the real filename however, they have no problem
saving the .jpg image in their cache. Another thing to look at is if
you disable caching somewhere in your im.php file via header() function
calls or something like that.

Reply With Quote
  #4 (permalink)  
Old 12-14-2004
Robert Tweed
 
Posts: n/a
Default Re: PHP image generation & caching

URLs with a querystring (i.e., ones that contain a "?") do not get cached by
the browser.

- Robert


Reply With Quote
  #5 (permalink)  
Old 12-14-2004
John Dunlop
 
Posts: n/a
Default Re: PHP image generation & caching

Robert Tweed wrote:

> URLs with a querystring (i.e., ones that contain a "?") do not get cached by
> the browser.


That depends on the caching directives. Responses to such
requests are cacheable if they include explicit expiration
times. See HTTP/1.1 sec. 13.9.

http://www.ietf.org/rfc/rfc2616.txt

--
Jock
Reply With Quote
  #6 (permalink)  
Old 12-15-2004
Chung Leong
 
Posts: n/a
Default Re: PHP image generation & caching

"Mr WZ Boson" <WZ_Boson@yahoo.co.uk> wrote in message
news:c1d9a813.0412131118.21a01b0e@posting.google.c om...
> Hello,
>
> I hope you can help - I'm a bit new to PHP.
>
> My basic problem is with a page (HTML) which is intended to display an
> image slideshow. On this page there are a number of links to click
> (one for each slideshow topic) and a "TV screen" to view the results.
>
> The images are stored on the server as (big) JPG files - and when they
> are downloaded for the slideshow, I resize them with a PHP script
> "im.php" :
>
> $filename = $_GET['filename'];
> header('Content-type: image/jpeg');
> .
> .... open $filename & do the resizing
> .
> imagejpeg( ...
>
>
> After a link is selected, I preload the set of images with Javascript
> by doing :
>
> im[i].src = "php/im.php?filename=" + getFName(i); // for each in the
> set
>
> where getFname(i) returns the i'th image in the set.
>
> I then start the slideshow (I've got things in the Javascript to make
> sure all images are preloaded before starting)
>
> Now, my problem is that the browser doesn't seem to be caching the
> images and keeps making server requests during the slidehow (which
> rather defeats the idea of pre-loading)
>
> If I "cheat" and replace the preloading with :
>
> im[i] = getFName(i);
>
> it works fine (i.e I can switch the server off & it continues to show
> the slideshow).
>
> This happens with all browsers I've tried (IE6, Firefox, Netscape)
>
> Hope all this makes sense & would appreciate your expert advice.
>
> Mr WZ Boson


Well, if you want the browser to cache the images, then the images really
aren't dynamic now, are they? So why border serving them dynamically using a
PHP script? I mean you are making your server process the same image over
and over again. Just save the smaller versions of the images in a separate
folder and let the web server handle them.


Reply With Quote
  #7 (permalink)  
Old 12-15-2004
cyberhorse
 
Posts: n/a
Default Re: PHP image generation & caching

true, yet not always applicable. What if he changes the images very
often? It's much easier just to drop the new images in, rather than
making two copies of each image, etc. :) After all that's what
computers are for - to do the dirty and repetative job for us.
Of course on the other hand he can have a script to do the resizing
also automatically ... but that "if" situations are endless :)

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:34 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0