Jump to content

How to prevent session locks?


Martijn Geerts
 Share

Recommended Posts

PHP writes its session data to a file by default, so does ProcessWire. So when ProcessWire starts executing a process the session starts and the session gets locked. After the process is completed the session unlocks and we are able to use ProcessWire again. For normal scripts this is oké. But when you have long running processes like importing big data or you want to create a responsive AJAX API, this can be a real bottleneck. You see this 'issue' for example with ImportPagesCSV where the admin 'freezes' while importing.

1 Dirty way to avoid session lock for big data import is to remove all sessions after you have started the import script. But this will log you out from the admin. An other way could be to use exec() and send the output to /dev/null. (Running the script in background)

How do you guys deal with these session locks ?

  • Like 1
Link to comment
Share on other sites

There is also an example layer class on SO that provides none blocking concurent session writes: http://stackoverflow.com/questions/10046570/php-save-session-when-using-session-write-close/27993746#27993746

But you need to implement this yourself before you start the long running tasks and switch back to PWs regular behave after you have finished them.

You can use everything you want to handle sessions with http://php.net/manual/en/function.session-set-save-handler.php.

Edited by horst
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...