简体   繁体   English

Apache太多打开的文件(24)

[英]Apache Too many open files (24)

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. 由于对“打开的文件过多(24)”问题有很多答案,以及如何解决该问题,只是增加了允许的打开文件数限制,所以我没有找到任何建议来检查谁在使用这些文件。

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 致命错误:未捕获的异常“ Exception”,消息为“未知:open(/ var / lib / php / session / sess_375048d5pfne5cu3v0l3sjji04,O_RDWR)失败:打开的文件过多(24)”

Also I have restarted my apache process: 另外,我已经重新启动了我的Apache流程:

$ 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 ? 由于我的虚拟盒子机器实际上正在通过htop休眠,是否有任何工具可以检查谁在使用这些文件?

Look into the directory /var/lib/php ! 查看目录/var/lib/php You will find a lot of files starting with sess_ there. 您会在那里找到许多以sess_开头的文件。 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. 如果删除这些文件( rm -vf /var/lib/php/sess_* ),则所有当前访问者都将丢失其当前会话(他们需要重新登录到您的站点),但问题将得到解决。

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. 这个问题中,您可以找到如何在php中设置以自动删除过期的会话文件。 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. 在我看来,将session.cookie_lifetime设置为半小时左右,并将session.gc_maxlifetime设置为更长一点(例如35分钟)是可以的。

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. 如果您只有一个只有几个访问者的小型站点(每天最多几十个站点),那么每天从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. 在我看来,在这种情况下,最好将一些备用php会话解决方案与数据库后端一起使用。

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 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. find /var/lib/php -type f -name "sess_*" \\! -ctime 1440|xargs -P 1 -n 50 rm -vf将删除该目录中所有文件,从sess_开始,并且一天或更早。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM