【问题标题】:php zend framework http client errorphp zend框架http客户端错误
【发布时间】:2013-05-27 22:02:10
【问题描述】:

我正在尝试使用 zend 框架编写一段 php 代码。我正在使用 zend_http_client。代码随机运行!我的意思是,它有时工作正常,有时会得到一个空页面,并且来自 Apache 错误日志的此错误:

[Mon May 27 16:46:37 2013] [error] [client 4.4.4.4] PHP Warning:  require_once(/var/www/my.somesite.com/library/Zend/Http/Client/Adapter/Exception.php): failed to open stream: Too many open files in /var/www/my.somesite.com/library/Zend/Http/Client/Adapter/Socket.php on line 222
[Mon May 27 16:46:37 2013] [error] [client 4.4.4.4] PHP Fatal error:  require_once(): Failed opening required 'Zend/Http/Client/Adapter/Exception.php' (include_path='/var/www/my.somesite.com/application/../library:../application/models:.:/usr/share/php:/usr/share/pear') in /var/www/my.somesite.com/library/Zend/Http/Client/Adapter/Socket.php on line 222
[Mon May 27 16:46:37 2013] [error] [client 4.4.4.4] PHP Fatal error:  Undefined class constant 'PRIMARY_TYPE_NUM' in /var/www/my.somesite.com/library/Zend/Session/SaveHandler/DbTable.php on line 522

这样的php代码:

    public function Request($server_method, $params_arr) {
    $httpClient = new Zend_Http_Client;
    $httpClient->setConfig(array('timeout' => '900'));
    $client = new Zend_XmlRpc_Client ( Zend_Registry::getInstance ()->config->ibs->xmlrpc_url ,$httpClient);
    $request = new Zend_XmlRpc_Request ( );
    $response = new Zend_XmlRpc_Response ( );
    $request->setMethod ( $server_method );
    $request->setParams ( array ($params_arr ) );
    $client->doRequest ( $request, $response );
    if ($response->isFault ()) {
        $fault = $response->getFault ();
        //echo '<pre>' . $fault->getCode () . '' . $fault->getMessage () . '</pre>';
        $this->response = array (FALSE, $fault->getMessage () );
        return array (FALSE, $fault->getMessage () );
    }

    //return $response;
    $this->response = array (TRUE, $response->getReturnValue () );
    return array (TRUE, $response->getReturnValue () );
    //var_dump($response->getReturnValue());
}

问题出在哪里?

【问题讨论】:

    标签: php zend-framework httpclient


    【解决方案1】:

    问题可能与您的方法本身无关。

    您正在打开许多文件而不是关闭它们(套接字也算作文件打开)。套接字适配器本身有一个名为persistent的配置,设置false以防止TCP重用。

    尝试检查您的 http 客户端是否在使用结束时被正确销毁,并且没有在代码的其他位置引用(这会阻止垃圾收集器清理)。

    更多信息:

    ulimit -aH检查限制(打开文件数的最大限制)

    /etc/security/limits.conf也有一些数字

    soft nofile 1024

    hard nofile 65535

    您可以将 ulimit 增加 ulimit -n 65535echo 65535 &gt; /proc/sys/fs/file-max 以设置更高的值,但强烈建议不要这样做。

    要永久设置,在/etc/sysctl.conf 中设置fs.file-max=65535

    【讨论】:

    • 在我的/etc/security/limits.conf 值是* - 65535/proc/sys/fs/file-max 是`394882`!
    • 请检查http客户端对象在使用结束时是否被正确销毁
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-19
    • 1970-01-01
    相关资源
    最近更新 更多