Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection timed out after 10000 milliseconds in CURL and PHP Geocoder

Tags:

php

curl

I have a script with a loop in which I execute the PHP geocoder function. The loop has more than 1000 iterations and the whole process takes some time. This is my script:

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

The problem is I get an error:

(&quot;Connection timed out after 10000 milliseconds&quot;).

How can I increase the limit? I have added this on top of my screen but its only for PHP not for the curl request:

set_time_limit(0); 

Normally if I was using pure CURL and not integrated in the PHP Geocoder then I would do something like that:

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

But what should I do now?

like image 888
user1919 Avatar asked Jul 17 '15 09:07

user1919


1 Answers

Disclaimer

I built this by reading the docs, I don't have the package installed and couldn't test it.

Setting the timeout in ivory-http-adapter

The official way, from the docs:

$configuration->setTimeout(30);

https://github.com/egeloen/ivory-http-adapter/blob/master/doc/configuration.md

The code

// new curl
$curl = new \Ivory\HttpAdapter\CurlHttpAdapter();

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

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

// save config
$curl->setConfiguration($conf);

Short version

// curl + timeout (quick version)
$curl = new \Ivory\HttpAdapter\CurlHttpAdapter();
$curl->setConfiguration($curl->getConfiguration()->setTimeout(30));
like image 50
spenibus Avatar answered Sep 22 '22 19:09

spenibus