>백엔드 개발 >PHP 튜토리얼 >nginx - php failed to open stream: Too many open files in

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

WBOY
WBOY원래의
2016-06-06 20:19:262353검색

<code>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</code>
<code>// 从数据库取出一篇文章
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);
}</code>

下面的是出错的这个文件

<code>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');
        }
    }</code>

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

回复内容:

<code>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</code>
<code>// 从数据库取出一篇文章
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);
}</code>

下面的是出错的这个文件

<code>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');
        }
    }</code>

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

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

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

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

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

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

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.