致命错误 - 打开的文件太多 [英] Fatal Error - Too many open files

查看:21
本文介绍了致命错误 - 打开的文件太多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的新机器上运行 PHPUnit 测试并收到此错误:

I try to run PHPUnit Tests in my new machine and I get this error:

PHP 致命错误:未捕获的异常 'UnexpectedValueException' 带有消息 'RecursiveDirectoryIterator::__construct(/usr/lib/php/pear/File/Iterator):无法打开目录:/usr/lib/中打开的文件太多php/pear/File/Iterator/Factory.php:114

PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(/usr/lib/php/pear/File/Iterator): failed to open dir: Too many open files' in /usr/lib/php/pear/File/Iterator/Factory.php:114

同样的代码在老机器上运行良好...

The same code on the old machine run well...

新机环境:PHP 版本:PHP 5.3.21 (cli)旧版本:PHP 5.3.14

New machine environment: PHP Version: PHP 5.3.21 (cli) Older: PHP 5.3.14

PHPUnit每次输出:

PHPUnit output every time:

................EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 65 / 66 ( 98%)
E

Time: 34 seconds, Memory: 438.50Mb

There were 50 errors:

1) XXXXXXXXXXX
PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(/usr/lib/php/pear/File/Iterator): failed to open dir: Too many open files' in /usr/lib/php/pear/File/Iterator/Factory.php:114

推荐答案

这可能是对运行代码的服务器的限制.每个操作系统只允许一定数量的打开文件/句柄/套接字.当服务器被虚拟化时,这个限制通常会进一步降低.在 Linux 服务器上,您可以使用 ulimit -n 检查当前限制,如果您具有 root 访问权限,则可以使用相同的命令增加它.我假设Windows服务器也有一种方法.否则你无能为力(除了要求你的主机或管理员增加它).

This can be a limitation on the server where the code is running. Every operating system only allows for a certain number of open files/handles/sockets. This limit is usually further reduced when the server is virtualized. On a Linux server you can check the current limit with ulimit -n, if you have root access you can increase it with the same command. I assume there is a method for Windows server as well. Otherwise there is not much you can do about it (except ask your hoster or administrator to increase it).

更多可配置的限制:

/etc/security/limits.conf 中的更改

soft nofile 1024
hard nofile 65535

增加ulimit ulimit -n 65535echo 65535 >/proc/sys/fs/file-max 或在 /etc/sysctl.conf:

Increase ulimit by ulimit -n 65535 or echo 65535 > /proc/sys/fs/file-max or in /etc/sysctl.conf:

fs.file-max=65535

这篇关于致命错误 - 打开的文件太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆