I have a problem with a curl request in my php script that i have uploaded on my dedicated webserver. I know that this curl request work fine, because i have already tested on my local machine. I think this the problem come from my apache configuration or on my DNS. But i am not sure.
When i use curl_setopt($ch, CURLOPT_VERBOSE, true);
i get the following error message in my test_curlog.log on my dedicated server:
* Rebuilt URL to: http://example.org/
* Hostname was NOT found in DNS cache
* Hostname was NOT found in DNS cache
Here is the code that i use:
<?php
var_dump("MULTI CURL REQUEST");
$error_curl_log = __DIR__ . '/../../../../web/test_curlog.log';
$fp = fopen($error_curl_log, 'a+');
// Création des ressources cURL
$ch2 = curl_init();
$ch3 = curl_init();
// Définit l'URL ainsi que d'autres options
curl_setopt($ch2, CURLOPT_URL, "http://example.org");
curl_setopt($ch2, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_VERBOSE, true); //For debug
curl_setopt($ch2, CURLOPT_STDERR, $fp);
curl_setopt($ch3, CURLOPT_URL, "https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&q=Hello%20world");
curl_setopt($ch3, CURLOPT_HEADER, 0);
curl_setopt($ch3, CURLOPT_VERBOSE, true); //For debug
curl_setopt($ch3, CURLOPT_STDERR, $fp);
// Création du gestionnaire multiple
$mh = curl_multi_init();
// Ajoute les deux gestionnaires
curl_multi_add_handle($mh, $ch2);
curl_multi_add_handle($mh, $ch3);
$active = null;
// Exécute le gestionnaire
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
// Ferme les gestionnaires
curl_multi_remove_handle($mh, $ch2);
curl_multi_remove_handle($mh, $ch3);
curl_multi_close($mh);
die;
On my local machine i get this response on my browser:
So i should get the same on my dedicated server but i get this error: Maximum execution time of 60 seconds exceeded
because the curl request doesn't seem to find the url.
Any help will be appreciate.
Finally, i found the solution. It consist to add this condition in the while loop:
Like this:
I don't know why but it works