5

I have /etc/security/limits.conf set to the following:

nobody soft nofile 409600
nobody hard nofile 1024000
phpuser soft nofile 409600
phpuser hard nofile 1024000
httpd soft nofile 409600
httpd hard nofile 1024000
* soft nofile 409600
* hard nofile 1024000

However, php pages still display:

[...] failed to open stream: Too many open files [...]

Setting ulimit -n 10000 looks to only be a temporary fix.

I also have the following set:

fs.file-max = 20970800
net.core.somaxconn = 1024000
kern.maxfilesperproc = 16638400
kern.maxfiles = 819200

2 Answers 2

3

I see two potential problems.

Your limit may not apply to phpuser

phpuser may ignore your new limit because it might not use PAM to "log-in", so /etc/security/limits.conf would not apply. See this answer for more details.

The system wide limit is reached

Your are changing users processes limits. The kernel also has a system wide limit on the number of open file-handles.

This might be your problem. You can check the value like this:

$ sysctl fs.file-max
$ sysctl fs.file-nr

By default, file-max shoud be 10% of your available system memory in kB, which may not be a very big number: 4 GB RAM ~ 400000 files which is below the limit you are trying to set.

The documentation says:

The three values in file-nr denote the number of allocated file handles, the number of allocated but unused file handles, and the maximum number of file handles. Linux 2.6 always reports 0 as the number of free file handles -- this is not an error, it just means that the number of allocated file handles exactly matches the number of used file handles.

3
  • Is this normal? error: permission denied on key 'fs.file-nr' when you edit sysctl.conf
    – Jason
    Dec 17, 2013 at 22:39
  • You should rather edit fs.file-max. You can try something like sysctl fs.file-max=500000.
    – Totor
    Dec 17, 2013 at 22:46
  • @FrankThornton Also, I edited my answer for another possible problem (PAM).
    – Totor
    Dec 17, 2013 at 22:50
0

You can set ulimit permanently by editing limits.conf.check this link

http://singztechmusings.wordpress.com/2011/07/11/ulimit-how-to-permanently-set-kernel-limits-in-linux/

In case of php files see this thread too

https://stackoverflow.com/questions/15937515/failed-to-open-stream-too-many-open-files

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .