php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51264 Unable to disable implicit session locking
Submitted: 2010-03-10 17:52 UTC Modified: 2010-03-11 16:03 UTC
From: bugs dot php dot net_2010 at forskernet dot dk Assigned:
Status: Closed Package: Session related
PHP Version: 5.2.13 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
4 + 20 = ?
Subscribe to this entry?

 
 [2010-03-10 17:52 UTC] bugs dot php dot net_2010 at forskernet dot dk
Description:
------------
I would like to run to requests in parallel in the same session, i.e. have two instances of a php script run simultaneously.

To demonstrate, please see the attached code (it will print 60 | chars with a second in between):

Next, simply open two tabs in your browser and call the script from both tabs.

If it is working as I hope, you will notice that they will not run in parallel (as I was hoping), but instead the script will start executing in one of the tabs, while the other will appear to hang. After the script in this tabs finishes (after one minute), the next tab will start executing.

I have tried different approaches for achieving explicit locking, mainly using session_set_save_handler (http://theserverpages.com/php/manual/en/function.session-set-save-handler.php), but to no effect - the locking is effective no matter what I come up with.

These are some pages that mention solutions for explicit locking, but none appear effective:

- http://thwartedefforts.org/2006/11/11/race-conditions-with-ajax-and-php-sessions/

- http://www.tonymarston.co.uk/php-mysql/client-clones.html

- http://blog.perplexedlabs.com/2009/10/05/php-custom-session-handler/

So, it appears to me that session_set_save_handler() is buggy - or am I just naively hoping it will work for me for a purpose it doesn't support?


Test script:
---------------
<?php
print "[";

for($i = 0; $i < 100; $i++){
  $spaces.="<!-- bufferme -->";
} // for

//and then

for($i = 0; $i < 60; $i++){
  for($ii = 0; $ii < 200000; $ii++){
    //do something slow here
  } // for
  sleep(1);
  print "$spaces|";
  flush();
} // for

print "]";

?>

Expected result:
----------------
Both scripts running in parallel.

Actual result:
--------------
Scripts executing one at a time.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-10 18:28 UTC] johannes@php.net
-Type: Bug +Type: Feature/Change Request
 [2010-03-10 18:28 UTC] johannes@php.net
The session is locked to ensure no data is lost. You can call session_write_close() so the other process can access the session storage. Marking a feature request, maybe there's a better solution in future.
 [2010-03-10 19:27 UTC] bugs dot php dot net_2010 at forskernet dot dk
"You can call session_write_close() so the other process can access the session storage."

Excellent - do you have any details on how I can accomplish this?

Naively executing session_write_close(); as the first php line in the script apparently does not do any difference in allowing the second process to start executing.

At least in my case the no. 2 process/tab still waits the full minute before it begins to execute.
 [2010-03-11 16:03 UTC] bugs dot php dot net_2010 at forskernet dot dk
Argh - apparently some browsers (including firefox) chooses to internally serialize requests against identical urls.

So, in effect, two requests, like this:

http://localhost/script.php and
http://localhost/script.php

Will always be serialized, the second request will simply never start in the browser before the first is finished.

However, two requests, like this:

http://localhost/script.php and
http://localhost/script.php?instance=2

will run happily in parallel.

Go figure - spent a few hours on this one :-)

- If anyone would happen to know how to disable this behaviour in firefox, please let me know!

And - excuses for bothering you on this issue, of course.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 21:01:30 2024 UTC