Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP curl_init()无法初始化新的curl句柄_Php_Curl - Fatal编程技术网

PHP curl_init()无法初始化新的curl句柄

PHP curl_init()无法初始化新的curl句柄,php,curl,Php,Curl,我有一个带有函数curl和test的类代理,如下所示: class proxy { public static function test($thread){ do{ $t=fufunction($thread); $res=self::curl('http://foo.com/',$t); ... }while(1) } public static func

我有一个带有函数curl和test的类代理,如下所示:

    class proxy {
    public static function test($thread){
         do{
            $t=fufunction($thread);
            $res=self::curl('http://foo.com/',$t);
            ...
        }while(1)
    }
    public static function curl($url,$proxy){
            $ecurl = curl_init($url);
            if(!$ecurl) {echo "\nFAILED CURL for $url\n"; sleep(60);exit;}
            if(!empty($xhead) && is_array($xhead)) curl_setopt($ecurl, CURLOPT_HTTPHEADER, $xhead);
            curl_setopt($ecurl, CURLOPT_MAXCONNECTS, 100);
            curl_setopt($ecurl, CURLOPT_CONNECTTIMEOUT, 15);
            curl_setopt($ecurl, CURLOPT_TIMEOUT, 15);
            curl_setopt($ecurl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ecurl, CURLOPT_HEADER, FALSE);
            curl_setopt($ecurl, CURLOPT_PROXY, $proxy);
            $ret= curl_exec($ecurl);
            curl_close($ecurl);
            unset($ecurl);
            return $ret;
        }
    }
当我使用这个脚本时,它在大约30000个curl请求后失败,错误为curl\u init无法初始化新的curl句柄 我使用以下代码执行脚本:

new proxy();
proxy::test('.$thread.');
你想锁定一些资源吗?起初我认为问题是我忘记关闭curl连接,或者取消设置curl资源。。。我加了curl\u close$ecurl 取消设置$ecurl,但没有帮助


有没有办法在运行脚本时释放curl资源,或者至少知道curl中可用的套接字数量?

为什么要创建一个无限循环来创建指向同一端点的curl请求?在我看来,你似乎达到了某种系统资源限制,因为你创建请求的速度太快了。循环不是无限的。有带中断条件的内部代码,这些代码被删除以简化示例脚本。速度不是问题。可能由于某种原因,没有剩余的空闲套接字可供curl启动。。。但我不知道怎么检查这个。