timbarsness
New Pleskian
Plesk Version
# cat /usr/local/psa/version
12.5.30 Ubuntu 14.04 1205160608.09
I've seen this issue now on multiple servers and in two different functions, but the symptoms are the same. The underlying issue seems to be that PHP can't do a DNS lookup. We ran into it with mysql connections and now most recently with file_get_contents().
Running this test from the command line works great:
The issue is when trying to do a host lookup, we get a PHP warning and the lookup fails:
Question: How do I know how apache is doing a DNS lookup?
# cat /usr/local/psa/version
12.5.30 Ubuntu 14.04 1205160608.09
I've seen this issue now on multiple servers and in two different functions, but the symptoms are the same. The underlying issue seems to be that PHP can't do a DNS lookup. We ran into it with mysql connections and now most recently with file_get_contents().
I created a basic test to simplify the problem:<?php
$country = "portugal";
$zip = "4600";
$url = "https://maps.googleapis.com/maps/api/geocode/json?address=country ".urlencode($country)."%20".urlencode($zip)."&sensor=false&key=[key removed]";
$result_string = file_get_contents($url);
var_dump($result_string);
$country = "portugal";
$zip = "4600";
$url = "https://maps.googleapis.com/maps/api/geocode/json?address=country ".urlencode($country)."%20".urlencode($zip)."&sensor=false&key=[key removed]";
$result_string = file_get_contents($url);
var_dump($result_string);
Running this test from the command line works great:
string(1598) "{
"results" : [
{
"address_components" : [
{
"long_name" : "4600",
"short_name" : "4600",
"types" : [ "postal_code", "postal_code_prefix" ]
},
{
"long_name" : "Porto District",
"short_name" : "Porto District",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Portugal",
"short_name" : "PT",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "4600, Portugal",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 41.3752001,
"lng" : -7.892297900000001
},
"southwest" : {
"lat" : 41.1894451,
"lng" : -8.165546899999999
}
},
"location" : {
"lat" : 41.2615809,
"lng" : -8.024700500000002
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 41.3752001,
"lng" : -7.892297900000001
},
"southwest" : {
"lat" : 41.1894451,
"lng" : -8.165546899999999
}
}
},
"place_id" : "ChIJy6K-a9-4JA0RoM87DsHrABw",
"types" : [ "postal_code", "postal_code_prefix" ]
}
],
"status" : "OK"
}
"
The same from apache fails:"results" : [
{
"address_components" : [
{
"long_name" : "4600",
"short_name" : "4600",
"types" : [ "postal_code", "postal_code_prefix" ]
},
{
"long_name" : "Porto District",
"short_name" : "Porto District",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Portugal",
"short_name" : "PT",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "4600, Portugal",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 41.3752001,
"lng" : -7.892297900000001
},
"southwest" : {
"lat" : 41.1894451,
"lng" : -8.165546899999999
}
},
"location" : {
"lat" : 41.2615809,
"lng" : -8.024700500000002
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 41.3752001,
"lng" : -7.892297900000001
},
"southwest" : {
"lat" : 41.1894451,
"lng" : -8.165546899999999
}
}
},
"place_id" : "ChIJy6K-a9-4JA0RoM87DsHrABw",
"types" : [ "postal_code", "postal_code_prefix" ]
}
],
"status" : "OK"
}
"
The issue is when trying to do a host lookup, we get a PHP warning and the lookup fails:
AH01071: Got error 'PHP message: PHP Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/vhosts/[path-removed]/tim-test.php on line 32
PHP message: PHP Warning: file_get_contents(https://maps.googleapis.com/maps/ap...y portugal 4600&sensor=false&key=[key removed]): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/vhosts/[path-removed]/tim-test.php on line 32'
So, trying to resolve maps.googleapis.com fails when going through apache but works when run at the command line. Rebooting apache fixes the problem, but it will come back again. Adding a record to /etc/hosts also fixes the problem and makes it not come back, but isn't sustainable.PHP message: PHP Warning: file_get_contents(https://maps.googleapis.com/maps/ap...y portugal 4600&sensor=false&key=[key removed]): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /var/www/vhosts/[path-removed]/tim-test.php on line 32'
Question: How do I know how apache is doing a DNS lookup?