Since there's many answers to this question "Too many open files (24)" and how to solve it just increasing number of allowed open files limit i have not found any suggestion how to check who is using these files.
I'm getting this error:
Fatal error: Uncaught exception 'Exception' with message 'Unknown: open(/var/lib/php/session/sess_375048d5pfne5cu3v0l3sjji04, O_RDWR) failed: Too many open files (24)' in
Also I have restarted my apache process:
$ ps aux | grep apa
84:root 7528 0.0 0.1 102376 4908 ? Ss 11:11 0:00 /usr/sbin/apache2 -k start
85:www-data 7531 0.0 0.0 101528 2952 ? S 11:11 0:00 /usr/sbin/apache2 -k start
86:www-data 7532 0.0 0.1 1309308 7168 ? Sl 11:11 0:00 /usr/sbin/apache2 -k start
87:www-data 7533 0.0 0.1 1309308 7312 ? Sl 11:11 0:00 /usr/sbin/apache2 -k start
91:vagrant 7748 0.0 0.0 8860 648 pts/0 S+ 11:20 0:00 grep --color=auto -in apa
Is there any tool to check who's using these files since my virtual box machine actually is sleeping by htop
?
Look into the directory /var/lib/php
! You will find a lot of files starting with sess_
there. These files contain the session data of your visitors.
How can you check, who is using these files:
lsof -n|grep -F /var/lib/php/sess_
will give you a process list, which processes are using them.
If you remove these files ( rm -vf /var/lib/php/sess_*
), all of your current visitors will lose their current session (they need to re-login into your site), but the problem will be solved.
A long-term solution would be to expire your sessions more often. In this question you can find, how can you set up in your php to automatically remove expired session files. On my opinion, setting session.cookie_lifetime
to around a half hour and session.gc_maxlifetime
a little bit longer (fe 35 minutes) is okay.
If you have only a small site with a few visitors (at most some tens daily), it is far enough if you delete the old session files daily from crontab.
If you have a big site, or you want a super user-friendly (but not so secure) site, you need to be able to handle a lot of sessions. On my opinion, in this case it is better if you use some alternate php session solution with a database backend.
The command find /var/lib/php -type f -name "sess_*" \\! -ctime 1440|xargs -P 1 -n 50 rm -vf
find /var/lib/php -type f -name "sess_*" \\! -ctime 1440|xargs -P 1 -n 50 rm -vf
will delete all files in this directory starting with sess_
and older as a day.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.