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
Best Answer
Short answer (for a 500000 limit)
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,
Or in simpler terms,
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:
and the program no longer crashes.
By the way, the system is a RHEL Server 6.6.