錯誤來自於php代碼,更具體地說 - facebook sdk。當Facebook的代碼會嘗試連接到IPv6地址,並不能達到網絡它拋出,很可能是由於IPv6的系統啓用,但沒有IPv6連接(引自base_facebook.php):
// 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);
}
}
}
正確的方式來處理這個問題將要麼禁用系統中的ipv6,要麼獲得一些ipv6連接。另外,它應該可以通過詢問Facebook的代碼總是被什麼東西在你的代碼中使用的IPv4這樣來取消錯誤:
Facebook::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
感謝您的回答,你能告訴我,我可以把那個片段中基的Facebook .PHP? – berkayk
該代碼片段用於_your_代碼,放在'require'/ path/to/facebook.php'後面。我不會推薦編輯base_facebook.php。這樣你就可以安全地從Facebook更新base_facebook.php。如果您可以編輯Facebook sdk,請將該選項直接放入[$ CURL_OPTS](https://github.com/facebook/facebook-php-sdk/blob/master/src/base_facebook.php#L133)數組中。 –
非常感謝。乾杯。 – berkayk