session_gc()
session_gc() — Perform session data garbage collection.
Built-in function of PHP 8.5. The manual lists it as available in PHP 7 >= 7.1.0, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
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().
Signature
session_gc(): int|false
Parameters
This function takes no parameters.
Return value
session_gc() returns the number of deleted session entries on success, or false on failure. Note: 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. 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.
Example
A runnable snippet:
// Note: This script should be executed by the same user of web server process. // Need active session to initialize session data storage access. session_start(); // Executes GC immediately session_gc(); // Clean up session ID created by session_start() session_destroy();
See also
session_start(), session_destroy()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page session_gc() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.