Fatal Error - Too many open files

前端 未结 8 1474
暖寄归人
暖寄归人 2020-12-08 02:22

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

PHP Fatal error: Uncaught exception \'UnexpectedValueException\' with message \'Re

相关标签:
8条回答
  • 2020-12-08 02:58

    After 'waking' my computer from sleep mode I ran into this problem.

    Restarting php-fpm like so fixed it. Classic turn it off & back on again solution.

    sudo /etc/init.d/php-fpm restart

    I think this may be related to xdebug which I recently added to php.

    0 讨论(0)
  • 2020-12-08 03:03

    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 limitations:

    In /etc/security/limits.conf 
      soft nofile 1024 
      hard nofile 65535 
    Increase ulimit by "ulimit -n 65535" 
    echo 65535 > /proc/sys/fs/file-max 
    In /etc/sysctl.conf 
      fs.file-max=65535 
    
    0 讨论(0)
  • 2020-12-08 03:03

    Don't store DirectoryIterator objects for later; you will get an error saying "too many open files" when you store more than the operating system limit (usually 256 or 1024).

    For example, this will yield an error if the directory has too many files:

    <?php 
    $files = array(); 
    foreach (new DirectoryIterator('myDir') as $file) { 
        $files[] = $file; 
    } 
    ?>
    

    Presumably, this approach is memory intensive as well.

    source: http://php.net/manual/pt_BR/directoryiterator.construct.php#87425

    0 讨论(0)
  • 2020-12-08 03:17

    I've noticed this occur in PHP when you forget to wrap something in a closure. Carefully look at your recent diffs and you might be able to get to the bottom of this (in my case, I referenced $faker in a Laravel PHP unit factory without having a closure.

    0 讨论(0)
  • 2020-12-08 03:19

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

    0 讨论(0)
  • 2020-12-08 03:19

    on server debian you can go to also to

    /etc/php/php7.xx/fpm/pool.d/www.conf

    rlimit_files = 10000

    /etc/init.d/php7.xx restart
    
    0 讨论(0)
提交回复
热议问题