Knowledgebase

The clean_user_php_sessions Script  Print this Article

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.

Was this answer helpful?

Related Articles

WHM Scripts
Overview: The cPanel & WHM installation process adds important scripts to your server’s...
The dbmaptool Script
Overview: You can use the /usr/local/cpanel/bin/dbmaptool script to grant ownership of databases...
The servers_queue Script
Overview: This script allows you to manage the task queue system. The task queue system allows...
The auto-adjust-mysql-limits Script
Overview: The /usr/local/cpanel/scripts/auto-adjust-mysql-limits script updates MySQL®...
The autossl_check Script
Overview: The /usr/local/cpanel/bin/autossl_check script allows you to manually check the SSL...