Description
In select instances, a PHP web application, if not configured properly, will begin to accumulate unnecessary PHP Session files that start to grow in size and will eventually lead to maxing out a partition in disk usage.
This commonly occurs in CMS's such as WordPress or Joomla that may have plugins that do not follow efficient coding standards in deleting unused PHP Session files.
Resolution
To resolve this, cPanel has developed the clean_user_php_sessions
script that will identify the session path by parsing the global php.ini
file, which would clean/remove any unused PHP session files in the configured directory.
The 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.
The location of this script can be found below:
# /usr/local/cpanel/scripts/clean_user_php_sessions
By default, the script will search for PHP session files in the following naming convention:
/sess_.*/
If your web application is configured to store the PHP session files in a different format, this would need to be adjusted by passing in a regex as the second parameter.
Example:
/usr/local/cpanel/scripts/clean_user_php_sessions 'ci_session\w+$'
To learn more about the script, you can review the following documentation:
cPanel Documentation - The clean_user_php_sessions Script