@@ -446,6 +446,39 @@ particular cookie by reading the ``getLifetime()`` method::
446
446
The expiry time of the cookie can be determined by adding the created
447
447
timestamp and the lifetime.
448
448
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
+
449
482
.. _session-database :
450
483
451
484
Store Sessions in a Database
0 commit comments