1111 <type class =" union" ><type >int</type ><type >false</type ></type ><methodname >session_gc</methodname >
1212 <void />
1313 </methodsynopsis >
14- <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.
18- </para >
19- <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.
25- </para >
26- <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.
32- </para >
14+ <simpara >
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:
18+ </simpara >
19+ <simplelist >
20+ <member >Low traffic sites may not have their session data deleted within the preferred duration.</member >
21+ <member >High traffic sites may have the garbage collector run too frequently, performing unnecessary extra work.</member >
22+ <member >Garbage collection is performed on the user's request, and the user may experience a delay.</member >
23+ </simplelist >
24+ <simpara >
25+ For production systems, it is recommended to disable the
26+ probability-based garbage collection by setting
27+ <link linkend =" ini.session.gc-probability" >session.gc_probability</link > to <literal >0</literal >
28+ and explicitly trigger the garbage collector periodically, for example by using "cron" on
29+ UNIX-like systems to run a script that calls <function >session_gc</function >.
30+ </simpara >
31+
32+ <note >
33+ <simpara >
34+ When calling <function >session_gc</function > from a command-line php script,
35+ the <link linkend =" ini.session.save-path" >session.save_path</link > must be set
36+ to the same value as web requests, and the script must have access and delete
37+ permissions for the session files. This may be affected by the user the script runs as,
38+ and container or sandboxing features such as systemd's <literal >PrivateTmp=</literal >
39+ option.
40+ </simpara >
41+ </note >
3342 </refsect1 >
3443
3544 <refsect1 role =" parameters" >
3948
4049 <refsect1 role =" returnvalues" >
4150 &reftitle.returnvalues;
42- <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.
50- </para >
51+ <simpara >
52+ <function >session_gc</function > returns the number of deleted session
53+ entries on success, &return.falseforfailure; .
54+ </simpara >
55+ <note >
56+ <simpara >
57+ Old session save handlers do not return the number of deleted session entries, but
58+ rather only a success/failure flag. If this is the case, <literal >1</literal > is returned regardless of
59+ how many session entries are actually deleted.
60+ </simpara >
61+ </note >
5162 </refsect1 >
5263
5364 <refsect1 role =" examples" >
5465 &reftitle.examples;
55- <para >
56- <example >
57- <title ><function >session_gc</function > example for task managers like cron</title >
58- <programlisting role =" php" >
66+ <example >
67+ <title ><function >session_gc</function > example for task managers like cron</title >
68+ <programlisting role =" php" >
5969<![CDATA[
6070<?php
6171// Note: This script should be executed by the same user of web server process.
@@ -66,18 +76,18 @@ session_start();
6676// Executes GC immediately
6777session_gc();
6878
69- // Clean up session ID created by session_gc ()
79+ // Clean up session ID created by session_start ()
7080session_destroy();
7181?>
7282]]>
73- </programlisting >
74- </example >
75- <example >
76- <title ><function >session_gc</function > example for user accessible script</title >
77- <programlisting role =" php" >
83+ </programlisting >
84+ </example >
85+ <example >
86+ <title ><function >session_gc</function > example for user accessible script</title >
87+ <programlisting role =" php" >
7888<![CDATA[
7989<?php
80- // Note: session_gc() is recommended to be used by task manager script, but
90+ // Note: session_gc() is recommended to be used by a task manager script, but
8191// it may be used as follows.
8292
8393// Used for last GC time check
@@ -97,20 +107,17 @@ if (file_exists($gc_time)) {
97107}
98108?>
99109]]>
100- </programlisting >
101- </example >
102- </para >
110+ </programlisting >
111+ </example >
103112 </refsect1 >
104113
105114 <refsect1 role =" seealso" >
106115 &reftitle.seealso;
107- <para >
108- <simplelist >
109- <member ><function >session_start</function ></member >
110- <member ><function >session_destroy</function ></member >
111- <member ><link linkend =" ini.session.gc-probability" >session.gc_probability</link ></member >
112- </simplelist >
113- </para >
116+ <simplelist >
117+ <member ><function >session_start</function ></member >
118+ <member ><function >session_destroy</function ></member >
119+ <member ><link linkend =" ini.session.gc-probability" >session.gc_probability</link ></member >
120+ </simplelist >
114121 </refsect1 >
115122</refentry >
116123<!-- Keep this comment at the end of the file
0 commit comments