我尝试在我的新机器上运行 PHPUnit 测试,但出现此错误:
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
同样的代码在旧机器上运行良好...
新机环境: PHP 版本:PHP 5.3.21 (cli) 较旧:PHP 5.3.14
PHPUnit每次输出:
................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服务器也有一种方法。否则你无能为力(除了要求你的主机或管理员增加它)。
更多可配置的限制:
/etc/security/limits.conf 中的更改
soft nofile 1024
hard nofile 65535
增加ulimit ulimit -n 65535
或 echo 65535 >/proc/sys/fs/file-max
或在 /etc/sysctl.conf
:
fs.file-max=65535
关于php - fatal error - 打开的文件太多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14748499/