Skip to content
Advertisement

Keeping a php script active

I was thinking of uploading some huge images onto my webpage and figured I could possibly optimize the load using a special image viewer with zoom functionality. As I’ve understood from long ago is that browsers have certain limits when it comes to image dimensions, and possibly memory as well. The workaround for the simple task of just displaying the image on a page would be to resize it server-side in PHP and display that.

However, with the idea of allowing zoom capabilities so one can look at all the little details (essentially seeing the picture as 1:1 scale), the problem I’m having is being able to provide that “zoom” quickly. As I understand it, a PHP script is run once when called, then cleared from memory when done. I made a test with a 40MB picture and imagecreatefrompng(); took 5 seconds, meaning each time a client zoomed (and panned), they’d have to wait 5 seconds before the image is updated.

The question becomes if it is possible to keep a PHP script running and have its memory preserved for the duration it’s needed? Like when a client clicks on a thumbnail, a call goes out to the PHP to load the image and it returns the resized image, but remains active and retains the $img in memory, waiting for more instructions. When the client zooms, a new call goes out to the PHP with the dimensions needed, and instead of having to reload the image it resizes and crops the original $img it still has in memory. When the client is done by closing the viewer, tab or browser, a call goes out to the PHP saying it’s done which triggers it to imagedestroy(original);, clear memory, and stop.

(maybe have some kind of timeout for cases when the client unexpectedly shuts down and no “stop” signal is sent)

Advertisement

Answer

As you are having really big images I would consider creating tiles once the image is uploaded and then use a JS library to handle the display and zoom functionnality like most map libraries. OpenSeadragon is typically one of these.

For the tiles generation, you could use Deepzoom or Zoomify as they are made to work with OpenSeadragon.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement