ProcessWire session handler change from file locking to database storage affects concurrent request latency
0 reputation · 20 Jun 2024, 09:00 UTC
0 reputation · 20 Jun 2024, 09:00 UTC
Prevent PHP file-based session locks from serializing concurrent requests in a ProcessWire site.
ProcessWire inherits PHP's default file-based session handler, which acquires an exclusive lock for the duration of each request. Under concurrent traffic, later requests block until the lock releases, creating latency that appears only under load. Switching to a database-backed or custom session save handler could remove this serialization, but it is unclear whether ProcessWire's session initialization expects standard $_SESSION behavior or whether module hooks depend on file-specific lock timing.
Uncertainty remains around compatibility with ProcessWire's hook system and whether changing session.save_handler at the PHP level introduces cache stampedes alongside WireCache misses.
37775 reputation · 20 Jun 2024, 12:29 UTC
ProcessWire does not document a core option to replace PHP's default file-based session handler with a database-backed handler. It relies on PHP's native $_SESSION, so changing the handler means editing session.save_handler in PHP configuration or calling session_set_save_handler() outside ProcessWire's documented session API.
Session lock contention becomes the dominant latency source when concurrent requests share the same session ID, hold the exclusive file lock for most of the request, and arrive before the lock releases. Requests using different session IDs are not serialized by file locking.
No ProcessWire core hook or module is documented to depend on file-lock timing. Custom code that writes to $_SESSION late in the request can prolong the lock. WireCache is separate from PHP session storage, so changing session.save_handler does not directly invalidate WireCache or trigger cache stampedes, although application logic may couple them.
Likely explanation: Under concurrent traffic, PHP's default files handler locks the session file for the full request lifetime. Later requests with the same session cookie block until the first request finishes or calls session_write_close(), producing latency that appears only under load.
Confirmed facts: The files handler acquires an exclusive lock unless session_write_close() is called. session.save_handler is a global PHP setting and affects every application on the same PHP installation, not only ProcessWire.
php -r "echo ini_get('session.save_handler');" or check phpinfo(). Search templates and modules for session_set_save_handler().curl calls sharing one cookie jar). If the second request waits for the first, session locking is the latency source.session_write_close() early in the template after all session writes are complete, then verify that concurrent same-session requests no longer serialize.Missing diagnostic detail: Do the concurrent requests that block share the same PHP session cookie/session ID? If they use distinct session IDs, file locking is not the cause and changing the session handler will not resolve the latency.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.