PHP Session Cleanup failing

Created:

2016-11-16 13:15:26 UTC

Modified:

2017-08-17 08:29:50 UTC

2

Was this article helpful?


Have more questions?

Submit a request

PHP Session Cleanup failing

Applicable to:

  • Plesk 10.x for Linux
  • Plesk 12.5 for Linux
  • Plesk 11.x for Linux
  • Plesk 12.0 for Linux

Symptoms

The article is applies to RPM based OS.

  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. Check the size of directory /var/lib/php/session file:
    # du -h /var/lib/php/session
    328M /var/lib/php/session

If directory file size is larger than 1 MB, it is needed to recreate it:

    # rm -rf /var/lib/php/session
# mkdir /var/lib/php/session
# chmod 1733 /var/lib/php/session/

If directory file size is equal or less than 1 MB, then:

  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
  3. Re-run the required Cron Job and check that it completes successfully .

Have more questions? Submit a request
Please sign in to leave a comment.