failed to open stream too many open files - php 1024 maximum limit - Redhat - why isn't new limit working?
Short answer (for a 500000 limit)
- Edit /etc/security/limits.conf and add this to the end of the file:
* hard nofile 500000 * soft nofile 500000 root hard nofile 500000 root soft nofile 500000
- Edit file /etc/sysconfig/httpd and add at the end add:
ulimit -n 500000
Reboot (don't know if it is absolutely necessary)
Bingo!
Long answer
Turns out that, according to Make ulimits work with start-stop-daemon and this Red Hat mailing list discussion,
limits.conf(5) is the configuration for pam_limits(8), which is activated by the PAM stack according to the configuration in /etc/pam.d. However, start-stop-daemon(8) as launched from an init.d script doesn't pass through the PAM stack, so those kinds of settings are never applied.
Or in simpler terms,
/etc/security/limits.conf applies to logins, and user "apache" isn't logging in.
The solution proposed in the first link is to edit the init.d script, and add the ulimit -n to the end of the script.
However, as can be observed in the second link, if you edit the /etc/init.d/httpd script, a system update can overwrite the file and the changes would go away.
So that's why they suggested here, here and here to edit the /etc/sysconfig/httpd file instead and enter the command there.
That's what I did, and now I got a beautiful cat /proc/pid/limits just how I wanted:
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 10485760 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 500000 500000 processes
Max open files 500000 500000 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 95124 95124 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
and the program no longer crashes.
By the way, the system is a RHEL Server 6.6.
Related videos on Youtube
glfabro
Updated on September 18, 2022Comments
-
glfabro over 1 year
I've got this message while debugging a problem in a PHP program.
- I've already edited the /etc/security/limits.conf and added
* hard nofile 500000 * soft nofile 500000 root hard nofile 500000 root soft nofile 500000
as instructed here (https://rtcamp.com/tutorials/linux/increase-open-files-limit/). After that, typing
ulimit -Hn
and
ulimit -Sn
reveals the new limit, 500000.
- I've already edited the /etc/pam.d/common-session file and added the line
session required pam_limits.so
I've then rebooted the system. My program continues to throw an exception when it tries to open file #1025.
I got the php process PID (27263) and then did a cat /proc/27263/limits
Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 10485760 unlimited bytes Max core file size 0 unlimited bytes Max resident set unlimited unlimited bytes Max processes 95124 95124 processes Max open files 1024 4096 files Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 95124 95124 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us
As you can see, even after setting those system wide configurations, the PHP process still has a 1024 max open files limit.
Why?? How can I change that? Why aren't the system wide settings working for this particular case?
Thank you