Re: Can a script run twice?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2006-05-24 at 09:44, tedd wrote:
> At 7:19 AM +0100 5/24/06, Stut wrote:
> >PHP is not 'sequential' and I have no idea where you got that 
> >impression. If the browser puts in a request to the server, the 
> >server will execute that request as soon as sufficient resources are 
> >free to do so. PHP does not 'lock' the session between requests. 
> >This is a problem being found by people trying AJAX with a session. 
> >Consider this sequence...
> >
> >1) User hits your button (ooh-err)
> >2) PHP starts processing the script and runs session_start() which 
> >loads the session data
> >3) User hits your button again
> >4) PHP starts processing the script a second time before the first 
> >run has finished, and loads the session data again for this new 
> >request
> >5) The execution started in 2) ends and commits the session data 
> >back to the session store
> >6) The execution started in 4) ends and commits the session data 
> >back to the session store
> 
> Nice explanation.
> 
> Ajax people are finding this happening w/o sessions.
> 
> Back to the posters problem, which is duplicate dB entries caused by 
> double clicking.
> 
> Apparently the problem isn't solvable by using tokens, sessions, 
> locking, and such. So why not just check the dB to see if the current 
> record has already been entered? If so, don't do it again.
> 
> Isn't this a solution? Or is there something here that I'm not understanding?

No the problem with ajax and sessions is usually scripts not releasing
the session as soon as they are done. In which case an ajax request
blocks all other requests with the same session. For instance I have
ajax requests that hit the webserver for slow feed requests that can
take up to 10 seconds. If I didn't manually close out the session, then
all other requests with the same session (either from browser or other
ajax requests) would block for about 10 seconds.

If ajax requests are seeing race conditions related to sessions then it
is usually due to a custom session implementation that doesn't perform
locking.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux