Skip to content

Instantly share code, notes, and snippets.

@masihyeganeh
Created March 14, 2014 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masihyeganeh/9551308 to your computer and use it in GitHub Desktop.
Save masihyeganeh/9551308 to your computer and use it in GitHub Desktop.
Weird PHP session lock
<?php
set_time_limit(0);
session_start();
print $_SESSION['something'];
<?php
set_time_limit(0);
session_start();
$_SESSION['something'] = 0;
for ($i=0; $i < 1000; $i++) {
$_SESSION['something']++;
sleep(10);
}
@masihyeganeh
Copy link
Author

If we execute writer.php, reader.php won't load until writer finishes completely

@masihyeganeh
Copy link
Author

OK, found the solution:

<?php

set_time_limit(0);

session_start();
$_SESSION['something'] = 0;
session_write_close();

for ($i=0; $i < 1000; $i++) { 
    session_start();
    $_SESSION['something']++;
    session_write_close();
    sleep(10);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment