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:
("Connection timed out after 10000 milliseconds").
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?
I built this by reading the docs, I don't have the package installed and couldn't test it.
The official way, from the docs:
$configuration->setTimeout(30);
https://github.com/egeloen/ivory-http-adapter/blob/master/doc/configuration.md
// 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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With