473,672 Members | 2,945 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 17 '05 #1
6 2615
Mr WZ Boson <WZ******@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.
Jul 17 '05 #2
I would also guess that browsers by now have learned not to cache
dynamic pages and when they see im.php?somethin g 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.

Jul 17 '05 #3
URLs with a querystring (i.e., ones that contain a "?") do not get cached by
the browser.

- Robert
Jul 17 '05 #4
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
Jul 17 '05 #5
"Mr WZ Boson" <WZ******@yahoo .co.uk> wrote in message
news:c1******** *************** ***@posting.goo gle.com...
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.
Jul 17 '05 #6
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 :)

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
3034
by: Mattias Campe | last post by:
Hi, Depending on if I get an image or a text of a certain URL, I want to do something different. I don't know in advance whether I'll get an image or a text. This is a URL that returns an image: http://indicator.amessage.info/indicator.php?param1=cobnet%40jabber.org&amp;param2=bounce&amp;param3=http%3A%2F%2Fstudent.ugent.be%2Fastrid%2Fpics%2Fjabber%2F&amp;param4=.png
2
6954
by: Mike Sobeiski | last post by:
Hi There! I'm developing a web project that requires to produce charts off the database and output it as image and presented to the user in a HTML document. (NOTE: Image is not directly streamed, but just linked in HTML output). The problem is, when user want to see the graph by changing parameters, they always have to click refresh to see the updated graph image. Although this problem doesn't occur on the local server.
7
3395
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
4
2686
by: Jake | last post by:
Does cookieless session state (with the sessionid embedded into the url) interfere with the browser's retrieval of cached images from one session to the next? Does the sessionid embedded into the url effectively limit client-side image caching to the lifetime of the session? Thanks Jake
1
1890
by: Giggle Girl | last post by:
Hello, I am helping to design a web application that uses 167 little icons on various pages in a framed environment. As is, the app loads each icon on a page by page basis, and if an image changes (like a "plus" becomes a "minus" when a folder icon is expanded) is does a document.all.src="picsV/minus.gif" which I am pretty sure goes and grabs the image at that moment, making no use of caching images at all.
9
1865
by: Mark Denardo | last post by:
This is related to another post I submitted, but I'll be more precise this time. I have a web page that contains an Image webcontrol that loads its image by: Image1.ImageUrl="<username>.jpg", and an option for the user to update the photo. If they click the update button, I then flip up a new panel, where I have a FileUpload control and corresponding Upload Button. If they load an image file and click the Upload button, my code uses...
0
1131
by: Cliff Smith | last post by:
Hi Group, In doing a website for a stamp maker, I have come across the following problem. I have a file called image_generator.php that creates a preview of the stamp. This uses GET vars for stamp height and width, but takes text, font and colour info from SESSION vars. This part works fine when the file is called as the image source.ie.
3
3605
by: computer_guy | last post by:
Hi Everyone, I run into a problem. I am trying to write an aspx that can dynamically generate an image based on some input parameters. Things are very simple if the size of the parameters is small and I can put them on the URL and pass them in as HTTP GET. In my image generation script I just need to read the parameters and then pump out the right MIME type and the right image byte stream. It is also very easy to use:
6
2229
by: googletired | last post by:
Hello, I haven't made a XSL in quite sometime so i am very rusty. Basicly i want the XSL to display a defined image if one is not present in the XML. here is my current XSL and XML will be below that, hope you can help. <?xml version='1.0' encoding='utf-8' ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" encoding="ISO-8859-1" omit-xml-declaration="yes"/>
0
8498
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8418
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8630
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8694
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7458
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5718
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2833
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2084
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1831
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.