5

I am running a cron and output coming to my id and getting below as output:

/bin/sh: /usr/bin/php: Too many open files in system

Cron runs every 5 mins.

Have checked /var/logs/cron and cron is executed every 5 mins.

Sites are working fine on the server.

1
  • contact your server administrator, I bet you don't have root access – ajreal Aug 10 '11 at 12:55
8

This means your system ran out of file handles, either in your php or in another application. Make sure to close any files you open to free file handles.

To the number of handles of every program running, use (as root):

for p in $(ps -A -o pid); do
    nh=$(ls /proc/$p/fd  2>/dev/null | wc -l) &&
    exe=$(readlink -f /proc/$p/exe  2>/dev/null) &&
    echo "$p ($exe): $nh"
done

For a more verbose output, use lsof.

You can also increase the number of possible system file handles by modyfing /etc/security/limits.conf (which effects changes to /proc/sys/fs/file-max), and decrease it for the current terminal session with ulimit -n.

6
  • 1
    +1 In addition might be open processes. See docs.php.net/pclose – dogbane Aug 10 '11 at 12:47
  • @fyr Clarified. Is the new version accurate? – phihag Aug 10 '11 at 12:58
  • @phihag: yes i removed also my post to keep the answers less redundant – fyr Aug 10 '11 at 13:02
  • @fyr Your answer was actually quite good, and I see no detriment in having multiple answers focus on different parts of the solution. Incorporated some good parts. – phihag Aug 10 '11 at 13:12
  • When I checked messages log I found, ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value and script name,I checked memory_limit =256 MB in php.ini – Alok Aug 11 '11 at 4:31
0

Check how many files you have currently open in the system by:

$ sysctl kern.num_files

and what is your kernel limit by:

$ sysctl kern.maxfiles

To check which regular files are open, this command can help:

lsof | grep -w REG | less

If your limit is too low, then increase it by these commands (run as root):

sysctl -w kern.maxfiles=20480
sysctl -w kern.maxfilesperproc=4096

Note: Add sudo if required if running from the user account.

and try again.

To set it permanently, add it into your /etc/sysctl.conf:

kern.maxfiles=20480
kern.maxfilesperproc=4096

If you don't have access to change the limits, contact your hosting provider.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy