diff --git a/reference/session/functions/session-gc.xml b/reference/session/functions/session-gc.xml index 0f12d0b08d39..6082713a78fc 100644 --- a/reference/session/functions/session-gc.xml +++ b/reference/session/functions/session-gc.xml @@ -11,25 +11,34 @@ intfalsesession_gc - - session_gc is used to perform session data - GC (garbage collection). PHP does probability based session GC by - default. - - - Probability based GC works somewhat but it has few problems. 1) Low - traffic sites' session data may not be deleted within the preferred - duration. 2) High traffic sites' GC may be too frequent GC. 3) GC is - performed on the user's request and the user will experience a GC - delay. - - - Therefore, it is recommended to execute GC periodically for - production systems using, e.g., "cron" for UNIX-like systems. - Make sure to disable probability based GC by setting - session.gc_probability - to 0. - + + By default, PHP uses session.gc_probability + to run the session garbage collector probabilistically on each + request. There are some limitations with this approach: + + + Low traffic sites may not have their session data deleted within the preferred duration. + High traffic sites may have the garbage collector run too frequently, performing unnecessary extra work. + Garbage collection is performed on the user's request, and the user may experience a delay. + + + For production systems, it is recommended to disable the + probability-based garbage collection by setting + session.gc_probability to 0 + and explicitly trigger the garbage collector periodically, for example by using "cron" on + UNIX-like systems to run a script that calls session_gc. + + + + + When calling session_gc from a command-line php script, + the session.save_path must be set + to the same value as web requests, and the script must have access and delete + permissions for the session files. This may be affected by the user the script runs as, + and container or sandboxing features such as systemd's PrivateTmp= + option. + + @@ -39,23 +48,24 @@ &reftitle.returnvalues; - - session_gc returns number of deleted session - data for success, &false; for failure. - - - Old save handlers do not return number of deleted session data, but - only success/failure flag. If this is the case, number of deleted - session data became 1 regardless of actually deleted data. - + + session_gc returns the number of deleted session + entries on success, &return.falseforfailure;. + + + + Old session save handlers do not return the number of deleted session entries, but + rather only a success/failure flag. If this is the case, 1 is returned regardless of + how many session entries are actually deleted. + + &reftitle.examples; - - - <function>session_gc</function> example for task managers like cron - + + <function>session_gc</function> example for task managers like cron + ]]> - - - - <function>session_gc</function> example for user accessible script - + + + + <function>session_gc</function> example for user accessible script + ]]> - - - + + &reftitle.seealso; - - - session_start - session_destroy - session.gc_probability - - + + session_start + session_destroy + session.gc_probability +