-
Notifications
You must be signed in to change notification settings - Fork 830
Improve session_gc documentation #4970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,25 +11,34 @@ | |
| <type class="union"><type>int</type><type>false</type></type><methodname>session_gc</methodname> | ||
| <void/> | ||
| </methodsynopsis> | ||
| <para> | ||
| <function>session_gc</function> is used to perform session data | ||
| GC (garbage collection). PHP does probability based session GC by | ||
| default. | ||
| </para> | ||
| <para> | ||
| 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. | ||
| </para> | ||
| <para> | ||
| 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 | ||
| <link linkend="ini.session.gc-probability">session.gc_probability</link> | ||
| to 0. | ||
| </para> | ||
| <simpara> | ||
| By default, PHP uses <link linkend="ini.session.gc-probability">session.gc_probability</link> | ||
| to run the session garbage collector probabilistically on each | ||
| request. There are some limitations with this approach: | ||
| </simpara> | ||
| <simplelist> | ||
| <member>Low traffic sites may not have their session data deleted within the preferred duration.</member> | ||
| <member>High traffic sites may have the garbage collector run too frequently, performing unnecessary extra work.</member> | ||
| <member>Garbage collection is performed on the user's request, and the user may experience a delay.</member> | ||
| </simplelist> | ||
| <simpara> | ||
| For production systems, it is recommended to disable the | ||
| probability-based garbage collection by setting | ||
| <link linkend="ini.session.gc-probability">session.gc_probability</link> to <literal>0</literal> | ||
| and explicitly trigger the garbage collector periodically, for example by using "cron" on | ||
| UNIX-like systems to run a script that calls <function>session_gc</function>. | ||
| </simpara> | ||
|
|
||
| <note> | ||
| <simpara> | ||
| When calling <function>session_gc</function> from a command-line php script, | ||
| the <link linkend="ini.session.save-path">session.save_path</link> 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 <literal>PrivateTmp=</literal> | ||
| option. | ||
| </simpara> | ||
| </note> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="parameters"> | ||
|
|
@@ -39,20 +48,22 @@ | |
|
|
||
| <refsect1 role="returnvalues"> | ||
| &reftitle.returnvalues; | ||
| <para> | ||
| <function>session_gc</function> returns number of deleted session | ||
| data for success, &false; for failure. | ||
| </para> | ||
| <para> | ||
| 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. | ||
| </para> | ||
| <simpara> | ||
| <function>session_gc</function> returns the number of deleted session | ||
| entries on success, &return.falseforfailure;. | ||
| </simpara> | ||
| <note> | ||
| <simpara> | ||
| 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, <literal>1</literal> is returned regardless of | ||
| how many session entries are actually deleted. | ||
| </simpara> | ||
| </note> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="examples"> | ||
| &reftitle.examples; | ||
| <para> | ||
| <simpara> | ||
| <example> | ||
| <title><function>session_gc</function> example for task managers like cron</title> | ||
|
||
| <programlisting role="php"> | ||
|
|
@@ -66,7 +77,7 @@ session_start(); | |
| // Executes GC immediately | ||
| session_gc(); | ||
|
|
||
| // Clean up session ID created by session_gc() | ||
| // Clean up session ID created by session_start() | ||
| session_destroy(); | ||
| ?> | ||
| ]]> | ||
|
|
@@ -77,7 +88,7 @@ session_destroy(); | |
| <programlisting role="php"> | ||
| <![CDATA[ | ||
| <?php | ||
| // Note: session_gc() is recommended to be used by task manager script, but | ||
| // Note: session_gc() is recommended to be used by a task manager script, but | ||
| // it may be used as follows. | ||
|
|
||
| // Used for last GC time check | ||
|
|
@@ -99,18 +110,18 @@ if (file_exists($gc_time)) { | |
| ]]> | ||
| </programlisting> | ||
| </example> | ||
| </para> | ||
| </simpara> | ||
| </refsect1> | ||
|
|
||
| <refsect1 role="seealso"> | ||
| &reftitle.seealso; | ||
| <para> | ||
| <simpara> | ||
| <simplelist> | ||
| <member><function>session_start</function></member> | ||
| <member><function>session_destroy</function></member> | ||
| <member><link linkend="ini.session.gc-probability">session.gc_probability</link></member> | ||
| </simplelist> | ||
| </para> | ||
| </simpara> | ||
|
||
| </refsect1> | ||
| </refentry> | ||
| <!-- Keep this comment at the end of the file | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI: whitespace fix