CURL和PHP Geocoder中的连接在10000毫秒后超时

CURL和PHP Geocoder中的连接在10000毫秒后超时,php,curl,Php,Curl,我有一个带有循环的脚本,在其中执行PHP geocoder函数。 循环有1000多次迭代,整个过程需要一些时间。 这是我的剧本: for ($x = 0; $x < 1000; $x++) { //////////////////////////////////////////////////// // GECODE THE ADRESS AND GET THE COORDS $curl = new \Ivory\HttpAdapter\CurlHttpAdapter();

我有一个带有循环的脚本,在其中执行PHP geocoder函数。 循环有1000多次迭代,整个过程需要一些时间。 这是我的剧本:

for ($x = 0; $x < 1000; $x++) { 

////////////////////////////////////////////////////
// GECODE THE ADRESS AND GET THE COORDS
$curl     = new \Ivory\HttpAdapter\CurlHttpAdapter();

$geocoder = new \Geocoder\Provider\BingMaps($curl,$bingApikey);
//$geocoder = new \Geocoder\Provider\MapQuest($curl,$mapQuestApikey);
//$geocoder = new \Geocoder\Provider\ArcGISOnline($curl);
//$geocoder = new \Geocoder\Provider\OpenStreetMap($curl);


$result =  $geocoder->geocode($matchesAdressRightValues[$x][0]);

if (count($result)==0 || count($result)>1 ){
    $bingSucUn = 'not_success'; 
    array_push($arraySucUnsucBing,$bingSucUn);
}   
else {
    //echo ('result');
    //echo (count($result));
    //echo ('Endresult');
    $bingSucUn = 'success'; 
    array_push($arraySucUnsucBing,$bingSucUn);
}
//var_dump($result);
////////////////////////////////////////////////////
}  // end for
我怎样才能提高限额? 我已在屏幕顶部添加了此选项,但它仅适用于PHP,不适用于curl请求:

set_time_limit(0); 
通常,如果我使用的是纯CURL,而不是集成在PHP Geocoder中,那么我会这样做:

$ch = curl_init();
curl_setopt($ch,CURLOPT_TIMEOUT,1000);

但是我现在该怎么办呢?

我通过找到包含CurlHttpAdapter的php文件,成功地更改了CURL TIMEOUT选项。此文件的路径(在GEOCODER PHP安装中)为:

我评论了这两行:

//$this->configureTimeout($curl, 'CURLOPT_TIMEOUT');
//$this->configureTimeout($curl, 'CURLOPT_CONNECTTIMEOUT');
增加了这一行:

curl_setopt($curl, CURLOPT_TIMEOUT,0);

这就解决了这个问题。

我想你是在尝试做一项繁重的任务(或许多轻松的任务)。最好在web请求的异步调用中执行此操作,直接从操作系统调用脚本。此外,由于外部问题,此任务可能会失败,您需要连接到geocoder服务

我将从一个中运行它,并将结果记录到一个与web应用程序共享的数据库中。通过这种方式,应用程序可以检查任务执行情况并获得结果。请注意,此任务可能会失败,问题不在于超时(这只是问题的信使!)超时告诉您出了问题,您需要在其他地方找到它:服务器网络连接、您的主机、您请求的主机、您正在使用的库等

所以你必须采取不同的方法。祝你好运

免责声明 我是通过阅读文档构建的,我没有安装软件包,也无法测试它

在http适配器中设置超时 官方方式,从文件:

$configuration->setTimeout(30)

代码 短版

// curl + timeout (quick version)
$curl = new \Ivory\HttpAdapter\CurlHttpAdapter();
$curl->setConfiguration($curl->getConfiguration()->setTimeout(30));

我有类似的错误,这是由于代理设置。我已通过以下方式设置我的代理:

Sys.setenv(https_proxy="http://proxy:8000")

后来我可以下载了。

没有。不是复制品。这个问题集中在PHP Geocoder中CURL的使用上。啊,好吧,在我读了你的评论之后,我在谷歌上搜索了Geocoder的详细内容。也许这个
curlHttpAdapt
会有帮助:谢谢。这是一种比我所做的更合适的方法。我是象牙http适配器库的维护者,简短的回答是:
curl->getConfiguration()->setTimeout(30)
// new curl
$curl = new \Ivory\HttpAdapter\CurlHttpAdapter();

// get curl config
$conf = $curl->getConfiguration();

// set timeout
$conf->setTimeout(30);

// save config
$curl->setConfiguration($conf);
// curl + timeout (quick version)
$curl = new \Ivory\HttpAdapter\CurlHttpAdapter();
$curl->setConfiguration($curl->getConfiguration()->setTimeout(30));
Sys.setenv(https_proxy="http://proxy:8000")