Peter Frlicka wrote:
> 
> Hello.
> 
> What does apache + php do if the user refreshes a page 10 times in a while
> before the scripts finishes? do all 10 .php scripts finish or do the first 9
> get aborted? how can i solve the problem that when someone clicks a lot on a
> link (always the same link) the server gets overloaded (because the action
> taken in the script is somehow memory consuming). i need to ensure a user
> (www) can run only one instance of a .php script.
> 
> Peter Frlicka

See http://www.php.net/manual/en/features.connection-handling.php

I'm worried about why the user is clicking so much.  If your connection/processing 
really is going
to take a long time you could consider sending them the first bit of your page as 
quickly as
possible using "flush()".  That will take away any buttons/links they've clicked on 
(but not
Refresh), and at least make them feel something is happening!

However multiple clicking is a general problem with no great solutions.  It's a 
particularly
important issue for  on-line E-commerce applications when it is not only vital that 
the php script
complete but also that it should not be repeated.   For that you almost have to use a 
database to
record "transactions" (or at least the session variables which identify a 
"transaction").
 
I typically do the following : 

1. set ignore_user_abort

2. check to see if we have a record of this transaction, if we do check to see if it 
is complete. 
If it's complete
take them to a results/end page, if it's not complete take them to a holding page with 
an automatic
META-REFRESH to
the same url.

3. if we have no record of the transaction, create one, do the work, mark the 
transaction as
complete and show them the results/end page.

If the user only clicks once, everything proceeds smoothly and they get their results 
page as
normal.  

If the user clicks two or more times they go to a "holding" page with an automatic 
refresh which
keeps showing the same holding page until the first script completes and the next 
refresh takes them
to the results.

This is basically a safe approach but it's significant work unless you really need it! 

George

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to