Saltar al contenido

PHP Session Cleanup failing

Symptoms

  1. The folder containing PHP sessions has a large number of files:
    ~# ls -l /var/lib/php/session | wc -l 1139718 
  2. When running /etc/cron.hourly/plesk-php-cleanuper, CPU consumption increases to 100%.
  3. When attempting to find all working PHP session processes, this fails with the following error:
    ~# [ -x /usr/lib64/plesk-9.0/maxlifetime ] && [ -d /var/lib/php/session ] && find /var/lib/php/session -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib64/plesk-9.0/maxlifetime) ! -execdir fuser {} \; -delete Cannot open a network socket. Cannot open /proc directory: Too many open files fuser: error while loading shared libraries: libc.so.6: cannot open shared object file: Error 24 find: Failed to save working directory in order to run a command on `sess_fch2h2dm7s73t0g09r3dmepdp0': Too many open files 

Cause

The script plesk-php-cleanuper contains a string ! -execdir fuser {} \, which opens every file in the/var/lib/php/session directory and checks that it is not used by a working process and can be deleted. However, the maximum number of open files is set to 1024 by default.

Resolution

  1. Clear /var/lib/php/session using this script without the checker:
    ~# [ -x /usr/lib64/plesk-9.0/maxlifetime ] && [ -d /var/lib/php/session ] && find /var/lib/php/session -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib64/plesk-9.0/maxlifetime) -delete 
  2. Increase the limit for open files to the required value.

To get the maximum number of open files, run:

 ~# ulimit -a open files (-n) 1024 

Add ulimit -n 30480 to /etc/cron.hourly/plesk-php-cleanuper:

 ~#cat /etc/cron.hourly/plesk-php-cleanuper ~#!/bin/sh ~ulimit -n 30480 
  1. Re-run the required Cron Job and check that it completes successfully .