Setting ulimit correctly for PHP on Linux
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.
Related videos on Youtube
Jason
Updated on September 18, 2022Comments
-
Jason over 1 year
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
-
Jason over 10 yearsIs this normal? error: permission denied on key 'fs.file-nr' when you edit sysctl.conf
-
Totor over 10 yearsYou should rather edit
fs.file-max
. You can try something likesysctl fs.file-max=500000
. -
Totor over 10 years@FrankThornton Also, I edited my answer for another possible problem (PAM).