The clean_user_php_sessions Script

Valid for versions 82 through the latest version

Version:

82

Last modified: July 28, 2022


Overview

Use the /usr/local/cpanel/scripts/clean_user_php_sessions script to purge expired PHP sessions from a secure temporary directory. This script checks the session.gc_maxlifetime and session.save_path variables in the global php.ini file and determines when to remove the PHP session files.

  • This script only recognizes the global session.gc_maxlifetime PHP configuration value for each version of PHP.
  • If this script detects different values in the session.gc_maxlifetime variable, but the system stores the session data in a single location, the script uses the minimum value to determine when to purge expired session files.

For more information about PHP session files, read our MultiPHP INI Editor for WHM documentation.

Note:
  • This script requires root-level permission.
  • We recommend that this script runs at least once per day to remove old PHP session files.
  • When the /usr/local/cpanel/scripts/maintenance script runs, it adds the /usr/local/cpanel/scripts/clean_user_php_sessions script to the root user’s crontab.
  • If you customize the session.gc_maxlifetime value, but do not customize the session.save_path value, the script does not use the session.gc_maxlifetime variable value.

Run the script

When you run this script, the system only removes files with the session.save_path variable in a sess_* format by default.

Arguments

This script accepts the following arguments:

Option Description Example
A valid Perl Compatible Regular Expression (PCRE). A PCRE to match custom PHP session filenames. /usr/local/cpanel/scripts/clean_user_php_sessions '^ci_session[[:alnum:]]\{40}$'

Example

To clear out all PHP session files that match the custom example_session_* format, run the following command:

/usr/local/cpanel/scripts/clean_user_php_sessions '^ci_session[[:alnum:]]\{40}$'
Important:

Make certain the provided regular expression is specific so you do not remove any misconfigured session.save_path variables.

Additional Documentation