[英]Apache PHP/OSX Mavericks: - failed to open stream: Too many open files
I've recently upgraded to OSX Mavericks and since then, I've started getting the aforementioned error on my development machine. 我最近升级到OSX Mavericks,从那时起,我开始在我的开发机器上得到上述错误。 There is no obvious problem in the code (it's an auto generated Yii sample application). 代码中没有明显的问题(它是一个自动生成的Yii示例应用程序)。 What has happened as part of upgrade to Mavericks is: 作为升级到小牛队的一部分发生的事情是:
Ever since, I'm getting this problem after maybe loading and reloading the website a few time. 从那时起,我在加载和重新加载网站几次之后就遇到了这个问题。 After this error occurs, my web server keeps returning the same error for any other application hosted on localhost. 发生此错误后,我的Web服务器将继续为localhost上托管的任何其他应用程序返回相同的错误。 I have to mention that static web pages are served up fine. 我必须提到静态网页服务很好。
I've seen several threads on this topic. 我见过几个线程关于这一主题。 Most point out to issues in code where file handles are not being closed properly, thereby crossing the open file limit threshold. 大多数人都指出代码中的问题是文件句柄未正确关闭,从而超过了打开文件限制阈值。 I also found this thread which seems to suggest this might be a zend debugger issue. 我也发现这个线程似乎暗示这可能是一个zend调试器问题。 There's also a bug report filed for php 5.2.x. 还有针对php 5.2.x提交的错误报告 。 Following the thread here , I tried the following: 在这里的帖子之后,我尝试了以下内容:
$ ulimit -a
which reports: 报道:
open files (-n) 256
Also, 也,
sysctl -a | grep files
returns, 回报,
kern.maxfiles = 12288
kern.maxfilesperproc = 10240
kern.maxfiles: 12288
kern.maxfilesperproc: 10240
kern.num_files: 3248
Another interesting thread suggests to raise this limit (currently 256) using: 另一个有趣的线程建议使用以下方法提高此限制(目前为256):
ulimit -n 1024
I've tried everything, but nothing seems to be working. 我已经尝试了一切,但似乎没有任何工作。 The problem is also not consistently reproducible. 问题也不能始终如一地重现。
I am wondering is using ulimit -n 1024
is going to affect apache, since from what I've read, it affects the number of files shell can have open. 我想知道是使用ulimit -n 1024
会影响apache,因为从我读过的内容来看,它会影响shell可以打开的文件数量。
Any help is appreciated. 任何帮助表示赞赏。
EDIT: 编辑:
apache
helps for a bit, till the error is encountered again. 重新启动apache
有所帮助,直到再次遇到错误。 Shamelessly stolen from http://docs.basho.com/riak/latest/ops/tuning/open-files-limit/#Mac-OS-X 从http://docs.basho.com/riak/latest/ops/tuning/open-files-limit/#Mac-OS-X无耻地偷走
To check the current limits on your Mac OS X system, run: 要检查Mac OS X系统上的当前限制,请运行:
$ launchctl limit maxfiles
The last two columns are the soft and hard limits, respectively. 最后两列分别是软限制和硬限制。
To adjust the maximum open file limits in OS X 10.7 (Lion) or newer, edit /etc/launchd.conf and increase the limits for both values as appropriate. 要调整OS X 10.7(Lion)或更高版本中的最大打开文件限制,请编辑/etc/launchd.conf并根据需要增加这两个值的限制。
For example, to set the soft limit to 16384 files, and the hard limit to 32768 files, perform the following steps: 例如,要将软限制设置为16384文件,将硬限制设置为32768文件,请执行以下步骤:
Verify current limits: 验证当前限制:
$ launchctl limit
cpu unlimited unlimited
filesize unlimited unlimited
data unlimited unlimited
stack 8388608 67104768
core 0 unlimited
rss unlimited unlimited
memlock unlimited unlimited
maxproc 709 1064
maxfiles 10240 10240
Edit (or create) /etc/launchd.conf and increase the limits. 编辑(或创建) /etc/launchd.conf并增加限制。 Add lines that look like the following (using values appropriate to your environment): 添加如下所示的行(使用适合您环境的值):
limit maxfiles 16384 32768
Save the file, and restart the system for the new limits to take effect. 保存文件,然后重新启动系统以使新限制生效。 After restarting, verify the new limits with the launchctl limit command: 重新启动后,使用launchctl limit命令验证新限制:
$ launchctl limit
cpu unlimited unlimited
filesize unlimited unlimited
data unlimited unlimited
stack 8388608 67104768
core 0 unlimited
rss unlimited unlimited
memlock unlimited unlimited
maxproc 709 1064
maxfiles 16384 32768
If you are experiencing this issue while running Apache you can configure apache to increase the limit: 如果您在运行Apache时遇到此问题,可以配置apache以增加限制:
$ sudo vi /usr/sbin/apachectl
locate: ULIMIT_MAX_FILES=""
找到: ULIMIT_MAX_FILES=""
and change this line to something like: 并将此行更改为:
ULIMIT_MAX_FILES="ulimit 4096"
Then: sudo apachectl restart
然后: sudo apachectl restart
This will not work for CLI scripts. 这不适用于CLI脚本。 But adding a ulimit directly to your ~/.bash_profile
(or equivalent) should work for that purpose. 但是直接向~/.bash_profile
(或等效的)添加ulimit应该可以用于此目的。
This has the advantage of setting specific limits for apache and your terminal without affecting other apps. 这样做的好处是可以为apache和终端设置特定限制,而不会影响其他应用程序。
Also, you should be able to adapt this method to other OSs by substituting ulimit
with the command applicable to that environment. 此外,您应该能够通过将ulimit
替换为适用于该环境的命令来使此方法适用于其他操作系统。
I was running into the same issue on El Capitain. 我在El Capitain遇到了同样的问题。 Found an article here I owes due credit for the solution. 在这里找到一篇文章我应该归功于解决方案。 Follow the actions below: 请按照以下操作:
Adjusting Open File Limits To adjust open files limits on a system-wide basis on Yosemite and above, you need to create two configuration files. 调整打开文件限制要在Yosemite及更高版本的系统范围内调整打开文件限制,您需要创建两个配置文件。 The first is a property list (aka plist) file in /Library/LaunchDaemons/limit.maxfiles.plist that contains the following XML configuration: 第一个是/Library/LaunchDaemons/limit.maxfiles.plist中的属性列表(aka plist)文件,其中包含以下XML配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxfiles</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxfiles</string>
<string>65536</string>
<string>65536</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceIPC</key>
<false/>
</dict>
</plist>
This will set the open files limit to 65536. The second plist configuration file should be stored in /Library/LaunchDaemons/limit.maxproc.plist with the following contents: 这会将打开文件限制设置为65536.第二个plist配置文件应存储在/Library/LaunchDaemons/limit.maxproc.plist中,其中包含以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>limit.maxproc</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxproc</string>
<string>2048</string>
<string>2048</string>
</array>
<key>RunAtLoad</key>
<true />
<key>ServiceIPC</key>
<false />
</dict>
</plist>
Both plist files must be owned by root:wheel and have permissions -rw-r–r–. 两个plist文件必须由root:wheel拥有并具有权限-rw-r-r-。 Restart the system. 重启系统。
Also its recommended setting them for the user session in .bashrc and add: 还建议在.bashrc中为用户会话设置它们并添加:
ulimit -n 65536
ulimit -u 2048
Hope this helps. 希望这可以帮助。
I was probably suffering from information overload. 我可能正在遭受信息超载。 A possible explanation is offered here which I've also mentioned in my original post. 这里提供了一个可能的解释,我在原帖中也提到过。 I guess I missed the little detail where the OP mentions that he's working on Mac OSX 10.8.x. 我想我错过了OP提到他在Mac OSX 10.8.x上工作的小细节。 I'm on 10.9 so I downloaded the zenddebugger.so from the page and things are looking good. 我在10.9,所以我从页面下载了zenddebugger.so,看起来很不错。 Haven't gotten a single too many open files
all day. 没有一整天too many open files
。
So, perhaps it was a ZendDebugger issue. 所以,也许这是一个ZendDebugger问题。
Regarding the debugger patch answer above. 关于上面的调试器补丁答案。 Unfortunately the answer provided above won't work for me, as it applies to php versions 5.4 and I must limit myself to php 5.3. 不幸的是,上面提供的答案对我不起作用,因为它适用于php版本5.4,我必须限制自己到php 5.3。
Zend has released version 6.3 of their server, which supports php at 5.3. Zend发布了他们的服务器版本6.3,它支持5.3的php。 I have been playing with the installation for a little while (after dropping my ulimit back down to Apple's default) to test it and am not experiencing any problems. 我已经玩了一段时间的安装(在将我的ulimit放回到Apple的默认值之后)来测试它并且没有遇到任何问题。 Before the upgrade I could not do any php debugging without raising that limit. 在升级之前,我无法在不提高限制的情况下进行任何php调试。
根据http://forums.zend.com/viewtopic.php?t=110823&start=10#p219438我认为这实际上只是在6.2中修复的Zend Server中的一个错误。
Got the same error with running xDebug. 运行xDebug时出现同样的错误。 An upgrade solved the issue. 升级解决了这个问题。
see: 看到:
https://superuser.com/questions/787888/too-many-files-open-on-mac-osx-after-running-apache-in-php-with-xdebug-for-som/829413#829413 https://superuser.com/questions/787888/too-many-files-open-on-mac-osx-after-running-apache-in-php-with-xdebug-for-som/829413#829413
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.