Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fallback to IPv6 when there's no Global Scope IPv6 connectivity #28

Merged
merged 1 commit into from

3 participants

@psaab

Hosts which have IPv6 enabled, but no IPv6 connectivity will attempt to fall back to IPv6 if IPv4 connections fail and will get back an error 'Network is unreachable'. Handle this case and retry over IPv6 only rather than provide a cryptic message

@scottmac scottmac merged commit 71976b0 into from
@heshanlk

Force IPv4 check there
Require PHP 5.3 or later - see https://bugs.php.net/bug.php?id=47739

-- Please add that to the README

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 20, 2012
  1. Fix case where server has IPv6 configured, but does not have Global

    Paul Saab authored
    IPv6 connectivity.
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 0 deletions.
  1. +19 −0 src/base_facebook.php
View
19 src/base_facebook.php
@@ -882,6 +882,25 @@ protected function makeRequest($url, $params, $ch=null) {
$result = curl_exec($ch);
}
+ // With dual stacked DNS responses, it's possible for a server to
+ // have IPv6 enabled but not have IPv6 connectivity. If this is
+ // the case, curl will try IPv4 first and if that fails, then it will
+ // fall back to IPv6 and the error EHOSTUNREACH is returned by the
+ // operating system.
+ if ($result === false && empty($opts[CURLOPT_IPRESOLVE])) {
+ $matches = array();
+ $regex = '/Failed to connect to ([^:].*): Network is unreachable/';
+ if (preg_match($regex, curl_error($ch), $matches)) {
+ if (strlen(@inet_pton($matches[1])) === 16) {
+ self::errorLog('Invalid IPv6 configuration on server, '.
+ 'Please disable or get native IPv6 on your server.');
+ self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
+ curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
+ $result = curl_exec($ch);
+ }
+ }
+ }
+
if ($result === false) {
$e = new FacebookApiException(array(
'error_code' => curl_errno($ch),
Something went wrong with that request. Please try again.