欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

nginx - php failed to open stream: Too many open files in

程序员文章站 2022-05-28 13:47:26
...
Warning: require_once(/mnt/hgfs/www/open/test/Requests-master/library/Requests/Exception.php): failed to open stream: Too many open files in /mnt/hgfs/www/open/test/Requests-master/library/Requests.php on line 136
PHP Fatal error:  require_once(): Failed opening required '/mnt/hgfs/www/open/test/Requests-master/library/Requests/Exception.php' (include_path='.:/usr/local/php/lib/php') in /mnt/hgfs/www/open/test/Requests-master/library/Requests.php on line 136

Fatal error: require_once(): Failed opening required '/mnt/hgfs/www/open/test/Requests-master/library/Requests/Exception.php' (include_path='.:/usr/local/php/lib/php') in /mnt/hgfs/www/open/test/Requests-master/library/Requests.php on line 136
// 从数据库取出一篇文章
include '../Requests-master/Request.php';
$article_cond='some cond';
$article=$db->fetchByCond($article_cond)
while($article)
{
    $return=Request::post($url,$data,$header);
    // do others
    $article=$db->fetchByCond($article_cond);
}

下面的是出错的这个文件

public static function autoloader($class) 
{
        // Check that the class starts with "Requests"
        if (strpos($class, 'Requests') !== 0) {
            return;
        }

        $file = str_replace('_', '/', $class);
        if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) {
            // 下面这行是136行
            require_once(dirname(__FILE__) . '/' . $file . '.php');
        }
    }

从数据库取出文章,然后用PHP Requests这个库将文章插入另一个服务器上的数据库(这里都是127.0.0.1)。不知道什么会出现这个问题,每插入1020篇文章就会出现这个问题,不知道是哪里设置的问题呢?

回复内容:

Warning: require_once(/mnt/hgfs/www/open/test/Requests-master/library/Requests/Exception.php): failed to open stream: Too many open files in /mnt/hgfs/www/open/test/Requests-master/library/Requests.php on line 136
PHP Fatal error:  require_once(): Failed opening required '/mnt/hgfs/www/open/test/Requests-master/library/Requests/Exception.php' (include_path='.:/usr/local/php/lib/php') in /mnt/hgfs/www/open/test/Requests-master/library/Requests.php on line 136

Fatal error: require_once(): Failed opening required '/mnt/hgfs/www/open/test/Requests-master/library/Requests/Exception.php' (include_path='.:/usr/local/php/lib/php') in /mnt/hgfs/www/open/test/Requests-master/library/Requests.php on line 136
// 从数据库取出一篇文章
include '../Requests-master/Request.php';
$article_cond='some cond';
$article=$db->fetchByCond($article_cond)
while($article)
{
    $return=Request::post($url,$data,$header);
    // do others
    $article=$db->fetchByCond($article_cond);
}

下面的是出错的这个文件

public static function autoloader($class) 
{
        // Check that the class starts with "Requests"
        if (strpos($class, 'Requests') !== 0) {
            return;
        }

        $file = str_replace('_', '/', $class);
        if (file_exists(dirname(__FILE__) . '/' . $file . '.php')) {
            // 下面这行是136行
            require_once(dirname(__FILE__) . '/' . $file . '.php');
        }
    }

从数据库取出文章,然后用PHP Requests这个库将文章插入另一个服务器上的数据库(这里都是127.0.0.1)。不知道什么会出现这个问题,每插入1020篇文章就会出现这个问题,不知道是哪里设置的问题呢?

Too many open files,这个提示说的很明白了,开发的文件太多了。

一个进程打开的文件数目是有上限的,无法超过这个值,require_once是要打开文件的,所以就出错了。

回到你的问题,单纯require是不应该达到文件打开上限的,两个方向来查问题吧

  1. 是否存在循环require的问题?

  2. 是否在其他位置open文件太多并且没有close?