- 
                Notifications
    
You must be signed in to change notification settings  - Fork 828
 
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
base: master
Are you sure you want to change the base?
Conversation
      
          
      
      
            jbafford
  
      
      
      commented
        Nov 1, 2025 
      
    
  
- Improve wording of the main body and return values sections
 - Minor updates to comments in the examples
 - Incorporate permissions note from PR session_gc: Add note regarding session.save_path and file access / permissions #4915
 
* Improve wording of the main body and return values sections * Minor updates to comments in the examples * Incorporate permissions note from PR php#4915
| to 0. | ||
| 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 0 | 
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.
| <link linkend="ini.session.gc-probability">session.gc_probability</link> to 0 | |
| <link linkend="ini.session.gc-probability">session.gc_probability</link> to <literal>0</literal> | 
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.
Some nits but mostly LGTM
| </para> | ||
| 
               | 
          ||
| <note> | 
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: failure
| </para> | |
| <note> | |
| </para> | |
| <note> | 
| <para> | ||
| <function>session_gc</function> is used to perform session data | ||
| GC (garbage collection). PHP does probability based session GC by | ||
| default. | ||
| 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: | ||
| </para> | 
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.
While at it might as well improve the tags.
| <para> | |
| <function>session_gc</function> is used to perform session data | |
| GC (garbage collection). PHP does probability based session GC by | |
| default. | |
| 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: | |
| </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> | 
| <para> | ||
| 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. | ||
| </para> | 
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.
| <para> | |
| 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. | |
| </para> | |
| <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> | 
| <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. | ||
| <function>session_gc</function> returns the number of deleted session | ||
| entries on success, &false; for failure. | ||
| </para> | 
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.
| <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. | |
| <function>session_gc</function> returns the number of deleted session | |
| entries on success, &false; for failure. | |
| </para> | |
| <simpara> | |
| <function>session_gc</function> returns the number of deleted session | |
| entries on success, &return.falseforfailure;. | |
| </simpara> | 
| <para> | ||
| Old session save handlers do not return number of deleted session data, but | ||
| rather only a success/failure flag. If this is the case, 1 is returned regardless of | ||
| how many session entries are actually deleted. | ||
| </para> | 
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.
| <para> | |
| Old session save handlers do not return number of deleted session data, but | |
| rather only a success/failure flag. If this is the case, 1 is returned regardless of | |
| how many session entries are actually deleted. | |
| </para> | |
| <simpara> | |
| Old session save handlers do not return number of deleted session data, but | |
| rather only a success/failure flag. If this is the case, 1 is returned regardless of | |
| how many session entries are actually deleted. | |
| </simpara> | 
| <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. | ||
| <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> | ||
| </para> | 
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.
The para tag is not needed.
| <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. | |
| <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> | |
| </para> | |
| <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> | 
Unless you want it to be part of the previous sentence in the markup, then move it into it and keep the <para> tag rather than replacing them with <simpara>.
* replace para with simpara * add literal tags * Fix CI whitespace issue
| &reftitle.examples; | ||
| <para> | ||
| <simpara> | ||
| <example> | ||
| <title><function>session_gc</function> example for task managers like cron</title> | 
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.
So this para tag is actually not needed at all
| <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> | 
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.
Ditto: the para tag is not actually needed, just have the simplelist directly.
| </simpara> | ||
| 
               | 
          ||
| <note> | 
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
| </simpara> | |
| <note> | |
| </simpara> | |
| <note> |