读写文件发生错误:Too many open files,如何解决?

EricWen

ubuntu系统
Warning: file_put_contents(/xxxx/log//17-03-22.txt): failed to open stream: Too many open files in /xxx/common/function.php on line 323

这是方法是写日志,用的是file_put_contents方法,按理说写完日志就关掉了文件连接了,而我的work就看了3个进程,就导致了这个问题,请问如何解决?

调试发现是curl_init造成的,但是有关闭,系统却一直保持连接

protected function _wget($url, $post_data = null)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($ch, CURLOPT_TIMEOUT, 15);
        if ($post_data) {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        }
        $response = curl_exec($ch);
        if ($response === false) {
            system_log('获取远程数据失败:' . curl_error($ch));
            curl_close($ch);
            return false;
        }
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        if ($http_code == 200) {
            $ret = json_decode($response, true);
            if ($ret) {
                return $ret;
            }
            system_log('获取远程数据返回异常内容:' . $response);
        } else {
            system_log('获取远程数据返回异常状态码:' . $http_code . ',返回内容为:' . $response);
            return false;
        }
    }

图片

7433 2 0
2个回答

walkor

http://php.net/manual/en/function.curl-setopt.php
这里有curl选项,应该有强制关闭复用链接的选项,找下

  • 暂无评论
JoeZing

兄弟,请问这个问题你解决了吗,同样碰到!

  • 暂无评论
年代过于久远,无法发表回答
🔝