Skip to content

Commit 622934c

Browse files
committed
minor #18149 Adding section "Configuring Garbage Collection" (ThomasLandauer)
This PR was merged into the 5.4 branch. Discussion ---------- Adding section "Configuring Garbage Collection" I just copied this over from https://symfony.com/doc/3.4/components/http_foundation/session_configuration.html#configuring-garbage-collection cause the info about `null` isn't mentioned anywhere else. Commits ------- 9c13550 Adding section "Configuring Garbage Collection"
2 parents fa8eae1 + 9c13550 commit 622934c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

session.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,39 @@ particular cookie by reading the ``getLifetime()`` method::
446446
The expiry time of the cookie can be determined by adding the created
447447
timestamp and the lifetime.
448448

449+
Configuring Garbage Collection
450+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
451+
452+
When a session opens, PHP will call the ``gc`` handler randomly according to the
453+
probability set by ``session.gc_probability`` / ``session.gc_divisor``. For
454+
example if these were set to ``5/100`` respectively, it would mean a probability
455+
of 5%. Similarly, ``3/4`` would mean a 3 in 4 chance of being called, i.e. 75%.
456+
457+
If the garbage collection handler is invoked, PHP will pass the value stored in
458+
the ``php.ini`` directive ``session.gc_maxlifetime``. The meaning in this context is
459+
that any stored session that was saved more than ``gc_maxlifetime`` ago should be
460+
deleted. This allows one to expire records based on idle time.
461+
462+
However, some operating systems (e.g. Debian) do their own session handling and set
463+
the ``session.gc_probability`` variable to ``0`` to stop PHP doing garbage
464+
collection. That's why Symfony now overwrites this value to ``1``.
465+
466+
If you wish to use the original value set in your ``php.ini``, add the following
467+
configuration:
468+
469+
.. code-block:: yaml
470+
471+
# config.yml
472+
framework:
473+
session:
474+
gc_probability: null
475+
476+
You can configure these settings by passing ``gc_probability``, ``gc_divisor``
477+
and ``gc_maxlifetime`` in an array to the constructor of
478+
:class:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\NativeSessionStorage`
479+
or to the :method:`Symfony\\Component\\HttpFoundation\\Session\\Storage\\NativeSessionStorage::setOptions`
480+
method.
481+
449482
.. _session-database:
450483

451484
Store Sessions in a Database

0 commit comments

Comments
 (0)