Veja aqui: link
Uma atualização causou esse problema.
De repente, nosso servidor php5.6-fpm do Ubuntu parou de funcionar com solicitações de curl.
Aqui está o que eu encontrei:
Funciona quando executado a partir do console php test.php
.
Funciona via wet a partir de console wget -qO- https://maps.google.com/maps/api/geocode/json?address=Brooklyn+NY+USA&key=AIzaSyBGgTVnShML1_WHJL0rOTEnt2XOrgVgnu4 | cat
Funciona usando o curl de console ums-admin@svr1:/var/www/propertymonitor.ae/htdocs/v2$ curl https://maps.google.com/maps/api/geocode/json?address=Brooklyn+NY+USA&key=AIzaSyBGgTVnShML1_WHJL0rOTEnt2XOrgVgnu4
No entanto, chamar o script via php-fpm no link não funciona e reclama sobre falha de pesquisa de DNS ?!
>Reiniciando o php5.6-fpm e ele começa a funcionar novamente!
Código abaixo:
<?php
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, "https://maps.google.com/maps/api/geocode/json?address=Brooklyn+NY+USA&key=AIzaSyBGgTVnShML1_WHJL0rOTEnt2XOrgVgnu4");
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$data = curl_exec($ch);
if ($data === false)
{
echo 'Curl error: ' . curl_error($ch);
} else {
echo 'Response: ' . $data;
}
// close curl resource to free up system resources
curl_close($ch);
?>
E o restante do sistema faz check-out:
cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com
E sem perda de pacotes:
64 bytes from 8.8.8.8: icmp_seq=3150 ttl=46 time=129 ms
64 bytes from 8.8.8.8: icmp_seq=3151 ttl=46 time=124 ms
64 bytes from 8.8.8.8: icmp_seq=3152 ttl=46 time=124 ms
64 bytes from 8.8.8.8: icmp_seq=3153 ttl=46 time=124 ms
^C
--- 8.8.8.8 ping statistics ---
3153 packets transmitted, 3153 received, 0% packet loss, time 3154312ms
rtt min/avg/max/mdev = 114.975/124.705/139.692/2.004 ms