While using the following Paypal IPN code I sometimes gets a "getaddrinfo failed" error and my script (to update a mySQL database via PHP) is not executed.
THE CODE
// read post from PayPal system and add 'cmd'
$postvars = array();
while (list ($key, $value) = each ($HTTP_POST_VARS)) {
$postvars[] = $key;
}
$req = 'cmd=_notify-validate';
for ($var = 0; $var < count ($postvars); $var++) {
$postvar_key = $postvars[$var];
$postvar_value = $$postvars[$var];
$req .= "&" . $postvar_key . "=" . urlencode ($postvar_value);
}
// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Connection: close\r\n";
$fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);
...
...
...
if (!$fp) {
echo $errstr . " (" . $errno . ")";
} else {
// UPDATE DB //
}
THE ERROR
php_network_getaddresses : getaddrinfo failed: Name or service not known (0)
What I don't get is that this happens pretty randomly, sometimes the whole script works fine. It seems to be totally independent of the variables received:
- subscr_id
- txn_type
- verify_sign
- etc etc...
I've contacted Paypal support a week ago but no reply so far.
Any help would be greatly appreciated. :)
P.S: I've just realised that the error comes from only one line.
$fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);