How to turn off implicit session locking in php?
Posted: Wed Mar 10, 2010 5:16 pm
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 code below (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 the two tabs will not execute in parallel, but instead the script will start executing in one of the tabs, while the other will appear to hang. After the script in the first 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 ... andler.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/r ... -sessions/
- http://www.tonymarston.co.uk/php-mysql/ ... lones.html
- http://blog.perplexedlabs.com/2009/10/0 ... n-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:
---------------
Expected result:
----------------
Both scripts running in parallel.
Actual result:
--------------
Scripts executing one at a time.
---
Further, I have had the suggestion of using session_write_close(); as the first php line in the script - but apparently this does not do any difference in allowing the second process to start executing.
Is there anyway to turn on explicit session locking in php?
To demonstrate, please see the code below (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 the two tabs will not execute in parallel, but instead the script will start executing in one of the tabs, while the other will appear to hang. After the script in the first 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 ... andler.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/r ... -sessions/
- http://www.tonymarston.co.uk/php-mysql/ ... lones.html
- http://blog.perplexedlabs.com/2009/10/0 ... n-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:
---------------
Code: Select all
<?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 "]";
?>
----------------
Both scripts running in parallel.
Actual result:
--------------
Scripts executing one at a time.
---
Further, I have had the suggestion of using session_write_close(); as the first php line in the script - but apparently this does not do any difference in allowing the second process to start executing.
Is there anyway to turn on explicit session locking in php?