PHP sessions enable us to store and retrieve data across multiple requests with the same client. Although HTTP is stateless, we can use cookies to store the current session ID, then store all of our data in a file or Redis key with this name. PHP allows us to configure the storage of session data with "save handlers" selected with the session.save_handler option.

Moodle's session subsystem represents PHP's save handlers as "session handlers" (e.g. database (the default), file, memcached and redis).

On every request, Moodle obtains a write lock over the session and reads the data contained within it. If the session lock is already held by another process Moodle will busy-wait for a configured period of time for the lock to become available, consuming one of the workers until it gives up and shows an error to the user. Unless explicitly freed with \core\session\manager::write_close() the session lock will continue to be held for the duration of the request, preventing other requests from progressing.

  1. Unable to obtain session lock