Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal Error - Too many open files

Tags:

php

phpunit

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

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...

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

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 
like image 793
Mauro Avatar asked Feb 07 '13 10:02

Mauro


People also ask

How do I increase too many open files in Linux?

In Linux, you can change the maximum amount of open files. You may modify this number by using the ulimit command. It grants you the ability to control the resources available for the shell or process started by it.


2 Answers

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).

More configurable limits:

Change in /etc/security/limits.conf

soft nofile 1024 hard nofile 65535 

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

fs.file-max=65535 
like image 140
Gerald Schneider Avatar answered Sep 30 '22 11:09

Gerald Schneider


How can you up file open limit (Linux or Max OS):

ulimit -n 10000 

Solves problem with phpunit or/and phpdbg and Warning: Uncaught ErrorException: require([..file]): failed to open stream: Too many open files in [...]

like image 20
pablorsk Avatar answered Sep 30 '22 11:09

pablorsk