Connection timed out after 10000 milliseconds in CURL and PHP Geocoder

I have a script with a loop in which I am executing a PHP geocoding function. The loop has over 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 that I am getting the error:

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

      

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

set_time_limit(0); 

      

Usually if I am using pure CURL and not integrated into PHP Geocoder then I would do something like this:

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

      

But what should I do now?

+3


source to share


4 answers


I had a similar error and it was related to my proxy settings. I have set up my proxy:

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

      



Later I was able to download.

+1


source


Renouncement

I built this by reading the docs, I do not have the package installed and cannot test it.

Setting timeout to ivory-http adapter

Official way from docs:

$ Config-> SetTimeout (30);

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



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));

      

+4


source


I think you are trying to do a hard task (or a lot of easy tasks). Better to do this when invoking a web request asynchronously , by calling the script directly from the operating system . Also this task may fail due to external problems, you need to connect to the geocoder service.

I would run this from a cron task and log the results to the database in conjunction with the web application. This way, the application can check the progress of the task and get the results. Note that this task may fail, and the problem is not a timeout (it's just a messenger problem!), Timeout tells you that something went wrong and you need to look for something elsewhere: the network connection to the server, your hosting, the host you are requesting, the library you are using, etc.

So, you have to take a different approach. Good luck!

+1


source


I was able to change the CURL TIMEOUT setting by finding the php file containing the CurlHttpAdapter. The path to this file (in the GEOCODER PHP installation):

vendor\egeloen\http-adapter\src

      

I have commented these two lines:

//$this->configureTimeout($curl, 'CURLOPT_TIMEOUT');
//$this->configureTimeout($curl, 'CURLOPT_CONNECTTIMEOUT');

      

and added this line:

curl_setopt($curl, CURLOPT_TIMEOUT,0);

      

This solved this problem.

0


source







All Articles