3

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);
Denis
  • 31
  • 1
  • 2
  • No offense but the way you create the body of the request is extremely complicated. The reported error message sounds more like a network/dns issue and not such much like a PHP problem. – Niko Jan 05 '13 at 12:22
  • I'm having this issue too. Did you get it resolved? – Jason Silver Feb 23 '16 at 13:20

1 Answers1

0

Is this still happening for you?
The cause would be that it's unable to resolve www.paypal.com - see if you can manually resolve www.paypal.com via your default nameserver. If this doesn't work, work with the provider of the nameserver, or switch to a different one (if possible).

Robert
  • 19,326
  • 3
  • 58
  • 59