1212 <void />
1313 </methodsynopsis >
1414 <para >
15- < function >session_gc</ function > is used to perform session data
16- GC (garbage collection). PHP does probability based session GC by
17- default.
15+ By default, PHP uses < link linkend = " ini. session.gc-probability " >session.gc_probability</ link >
16+ to run the session garbage collector probabilistically on each
17+ request. There are some limitations with this approach:
1818 </para >
1919 <para >
20- Probability based GC works somewhat but it has few problems. 1) Low
21- traffic sites' session data may not be deleted within the preferred
22- duration. 2) High traffic sites' GC may be too frequent GC. 3) GC is
23- performed on the user's request and the user will experience a GC
24- delay.
20+ < simplelist >
21+ < member >Low traffic sites may not have their session data deleted within the preferred duration.</ member >
22+ < member > High traffic sites may have the garbage collector run too frequently, performing unnecessary extra work.</ member >
23+ < member >Garbage collection is performed on the user's request, and the user may experience a delay.</ member >
24+ </ simplelist >
2525 </para >
2626 <para >
27- Therefore , it is recommended to execute GC periodically for
28- production systems using, e.g., "cron" for UNIX-like systems.
29- Make sure to disable probability based GC by setting
30- < link linkend = " ini.session.gc-probability " >session.gc_probability</ link >
31- to 0 .
27+ For production systems , it is recommended to disable the
28+ probability-based garbage collection by setting
29+ < link linkend = " ini.session.gc-probability " >session.gc_probability</ link > to 0
30+ and explicitly trigger the garbage collector periodically, for example by using "cron" on
31+ UNIX-like systems to run a script that calls < function >session_gc</ function > .
3232 </para >
33+
34+ <note >
35+ <para >
36+ When calling <function >session_gc</function > from a command-line php script,
37+ the <link linkend =" ini.session.save-path" >session.save_path</link > must be set
38+ to the same value as web requests, and the script must have access and delete
39+ permissions for the session files. This may be affected by the user the script runs as,
40+ and container or sandboxing features such as systemd's <literal >PrivateTmp=</literal >
41+ option.
42+ </para >
43+ </note >
3344 </refsect1 >
3445
3546 <refsect1 role =" parameters" >
4051 <refsect1 role =" returnvalues" >
4152 &reftitle.returnvalues;
4253 <para >
43- <function >session_gc</function > returns number of deleted session
44- data for success, &false; for failure.
45- </para >
46- <para >
47- Old save handlers do not return number of deleted session data, but
48- only success/failure flag. If this is the case, number of deleted
49- session data became 1 regardless of actually deleted data.
54+ <function >session_gc</function > returns the number of deleted session
55+ entries on success, &false; for failure.
5056 </para >
57+ <note >
58+ <para >
59+ Old session save handlers do not return number of deleted session data, but
60+ rather only a success/failure flag. If this is the case, 1 is returned regardless of
61+ how many session entries are actually deleted.
62+ </para >
63+ </note >
5164 </refsect1 >
5265
5366 <refsect1 role =" examples" >
@@ -66,7 +79,7 @@ session_start();
6679// Executes GC immediately
6780session_gc();
6881
69- // Clean up session ID created by session_gc ()
82+ // Clean up session ID created by session_start ()
7083session_destroy();
7184?>
7285]]>
@@ -77,7 +90,7 @@ session_destroy();
7790 <programlisting role =" php" >
7891<![CDATA[
7992<?php
80- // Note: session_gc() is recommended to be used by task manager script, but
93+ // Note: session_gc() is recommended to be used by a task manager script, but
8194// it may be used as follows.
8295
8396// Used for last GC time check
0 commit comments