You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`persistent`| whether to persist connections or not |
464
+
|`auth`| authentication parameters |
465
+
|`socket`| socket connection |
466
+
|`lockingEnabled`| enable session locking (see [Session Locking](#session-locking)) |
467
+
|`lockExpiry`| lifetime of the session lock in seconds |
468
+
|`lockRetries`| maximum number of lock acquisition attempts |
469
+
|`lockWaitTime`| microseconds to pause between lock acquisition attempts |
466
470
467
471
```php
468
472
<?php
@@ -616,6 +620,69 @@ without touching the storage leaves the last-modified time under the control of
616
620
`Stream` adapter's `gc()` removes session files whose modification time is older than the configured lifetime; an
617
621
overridden `updateTimestamp()` that does not touch the file must account for that.
618
622
623
+
### Session Locking
624
+
625
+
As of 5.14.2 the [Phalcon\Session\Adapter\Redis][session-adapter-redis] adapter can serialize concurrent requests
626
+
that share a session id. Without locking, two requests arriving with the same session cookie both read the session
627
+
data when they start and both write it back when they finish; the request finishing last overwrites whatever the
628
+
other one wrote. PHP's `files` handler prevents this by locking the session file for the duration of the request;
629
+
a storage backend such as Redis offers no equivalent protection by default.
630
+
631
+
-`Redis` supports locking through the constructor options listed below
632
+
-`Libmemcached`, `Stream` and `Noop` do not implement locking
633
+
- The session locking offered by the phpredis extension (`redis.session.locking_enabled`) applies only to its own handler (`session.save_handler = redis`) and has no effect on this adapter
634
+
635
+
Locking is disabled by default and is enabled with the `lockingEnabled` constructor option. When enabled, `read()`
636
+
acquires a per-session lock before returning the session data, and `close()` or `destroy()` releases it, so the
637
+
lock is held for the lifetime of the request. A second request for the same session id waits at `read()` until the
638
+
lock is released or its retries run out. The available options are:
|`Phalcon\Session\Exceptions\InvalidSessionName`|`Phalcon\Session\Exception`| The session name passed to `setName()` is not a valid identifier. |
814
881
|`Phalcon\Session\Exceptions\SessionAlreadyStarted`|`Phalcon\Session\Exception`|`start()` is called while a session is already active. |
815
882
|`Phalcon\Session\Exceptions\SessionModificationDenied`|`Phalcon\Session\Exception`| A write is attempted on a session whose state does not allow modification. |
816
-
|`Phalcon\Session\Adapter\Exceptions\AdapterRuntimeError`|`Phalcon\Session\Exception`| The underlying session adapter raises an unrecoverable I/O error. |
883
+
|`Phalcon\Session\Adapter\Exceptions\AdapterRuntimeError`|`Phalcon\Session\Exception`| The underlying session adapter raises an unrecoverable I/O error, or the session lock cannot be acquired (see [Session Locking](#session-locking)).|
817
884
|`Phalcon\Session\Adapter\Exceptions\InvalidSavePath`|`Phalcon\Session\Exception`| The configured save path is not a writable directory. |
818
885
|`Phalcon\Session\Adapter\Exceptions\SavePathUnavailable`|`Phalcon\Session\Exception`| The save path cannot be determined for the configured adapter. |
0 commit comments