title: Paypal IPN: random " php_network_getaddresses: getaddrinfo failed: Name or service not known (0)" error
body: <p>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.</p>
  
  <p><strong>THE CODE</strong>
  </p>
  
  <pre><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 &lt; count ($postvars); $var++) {
      $postvar_key = $postvars[$var];
      $postvar_value = $$postvars[$var];
      $req .= "&amp;" . $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 //
  }
  </code></pre>
  
  <p><strong>THE ERROR</strong></p>
  
  <pre><code>php_network_getaddresses : getaddrinfo failed: Name or service not known (0)
  </code></pre>
  
  <p>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:</p>
  
  <ul>
  <li>subscr_id</li>
  <li>txn_type</li>
  <li>verify_sign</li>
  <li>etc etc...</li>
  </ul>
  
  <p>I've contacted Paypal support a week ago but no reply so far.</p>
  
  <p>Any help would be greatly appreciated. :)</p>
  
  <p>P.S: I've just realised that the error comes from only one line.</p>
  
  <pre><code>$fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);
  </code></pre>