5.3. Static vs dynamic images
Prev | Chapter 5. Fundamentals of dynamic graph generation | Next

## 5.3. Static vs dynamic images

Having understood how we can generate images using a PHP script a new idea might be forming. There is nothing that says that we have to create the same image using the same data every time the graph script is called. We could for example randomly select a pre-stored image in a directory and every time we call (the same) graph script and new image is returned. Hence, with PHP scripts we can create dynamic images that generate different images depending on some yet to be specified parameters even though the script name stays the same. This is a new behaviour compared with our normal images.

This could also lead to a new, and very real, problem which has to do with the local caching most browsers do in order to avoid re-fetching already fetched objects such as images. Normally a browser will check the time stamp on the file on the server and compare with the latest fetched version it has stored locally. If the browser sees that the file on the server is older than what it already has it will not re-fetch the file.

Since a dynamic image is produced by a script and the script will stay the same even if the produced image is changing (due to new data) the browser might still think that the image has not changed since the script is the same and will not bother re-fetching it again. The exact behavior of the browser cache is usually adjustable by the end user and hence out of control for us who writes the script. A simple way to always force the client to re-fetch the dynamic image is described in Section 5.5.6

Prev | Up | Next
5.2. What is an image? | Home | 5.4. Dynamic images on the command line