Reputation: 16412
Is there anything like a session ID that prevents the same session for having multiple requests/threads at a time? How does it works?
I have a loop in a method of one of my controller classes of my application that loops waiting for some actions (checking database).
I you need to see code, the following is an excerpt of the code inside the method:
// Times in hundredths of seconds.
$timestamp = number_format(microtime(TRUE), 2, '', '');
$closing_time = $timestamp + ($auditorium_lot_timeout * 100);
// Loop until time's up.
do
{
usleep(250000); // Sleep 250ms to unload the CPU.
if (Model_Event::count_new_bids())
{
// Etc, etc, etc...
// Change closing time to wait 10 seconds more.
}
} while (number_format(microtime(true), 2, '', '') < $closing_time);
// After time's up, continue with closing the bids definitely.
// Perform some more actions.
The method to which this excerpt belongs is requested by AJAX. It's purpose is to close bids on an auction but wait some seconds before closing to give chance for last bids. For that it loops a preconfigured amount of time (like 30 seconds) and while it's looping, the entire application can't recieve any other request from the same user. Why is that? It's blocking me very hard because this user is the operator/auctioneer of the live auction and must send "bid" requests for users that are not participating online (but presential in a real auditorium), while he triggered this loop.
Update: JS request code is abstracted by CanJS models.
Upvotes: 1
Views: 208
Reputation: 255005
That happens because built-in sessions mechanism locks session file if some request still uses it.
So the possible solution for you is to release session in long living code by session_write_close()
PS: oh, haven't seen there is such comment from @chris. As a justification it is not a stealing an answer I put this link, that proofs I answered similar question before: https://stackoverflow.com/a/6405685/251311
Upvotes: 1