Web Hosting Talk







View Full Version : Preventing 'refresh' on forms


russx2
03-05-2003, 08:52 AM
Hi,

I have a script that takes some POST input and uses an external system call to ImageMagick to make an image. I am trying to put in 'protection' to stop the user pressing refresh multiple times (and lagging the server - each image takes approx 5 secs to produce).

I decided on a 'locking' mechanism where I create a temp file with their userid before calling the command and deleting it after (and checking for its existance at the beginning of the script.

However, what seems to be happening is that the server is 'queueing' the requests. With 2 browsers open, and both having 'refresh' pressed simultaneously (near enough) they take it in turns to execute, rather than both trying to execute simultaneously. Hence, the locking mechanism isn't working.

Any ideas? Is this normal behaviour for PHP? Can a session only 'access' one page at a time?

Cheers,
Russ

sasha
03-05-2003, 09:11 AM
Not sure if I understnd this correctlly the most simple way of handling this seems to be the session. Put the epoch time in the session and on refresh check if time is there and if it is check that 10 seconds are past from the last request.

luxline
03-05-2003, 04:48 PM
create a little tmp file with the browsers ip/datestamp. Each time a request is sent, if their ip is in there, and the timestamp is less than say 15 seconds old, its not processed.

Or of course use the sessions, sessions can access as many pages/files as they like.

Easiest way, get php to generate the form and in the form, have a hidden vairable SessionID. Before the imagemagick is called, create a lock file using the sessionid, and delete it after the imagemagick has completed. If the user presses refresh and the sessionid lock file is present, they get nothing/warning to be patient.

Or upgrade php to 4.3 - gd2 is included by default, and can handle images faster than imagemagick, but has less options of course!