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

  • 8 years later...

Reviving this thread.

Let's say I quickly opened 3 different pages in new browser tabs to edit in the admin that each take 10 seconds to load (assume they are pages with a lot of related data and repeater items).  Because of session locking, it must load the first page, then after that is completed loading, it will load the second page, and so on.  This means there is considerable lag.

I believe this is not an issue with ProcessWire itself (regardless if using SessionHandlerDB or file-based sessions), but how PHP does session locking in general to prevent issues.

So there's no problem-free way around this... is that still correct?

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...