为000webhost.com启用php中的curl扩展


enabling curl extension in php for 000webhost.com

所以我正在尝试将我的应用程序与facebook集成,我使用默认的示例.php的代码作为我的index.php。我已经更改了appID和appSecret以匹配我的应用的id和机密,每当我在facebook上测试代码时,它都会抛出一个异常,即UnhandledCurlException。每当我调用getUser()方法时,用try-and-catch包装代码只会返回0。

我知道我可以在php.ini上启用curl扩展,但我只能在本地主机上找到,而不能在我用来部署应用程序的服务器(000webhost.com)上找到。

我还听说可以使用.htaccess文件显式地修改php配置,从而启用curl扩展,有人知道如何做到这一点吗?或者还有其他我错过的选择吗?

这是引发错误的函数:受保护的函数makeRequest($url,$params,$ch=null){if(!$ch){$ch=curl_init();}

$opts = self::$CURL_OPTS;
if ($this->getFileUploadSupport()) {
  $opts[CURLOPT_POSTFIELDS] = $params;
} else {
  $opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
}
$opts[CURLOPT_URL] = $url;
// disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
// for 2 seconds if the server does not support this header.
if (isset($opts[CURLOPT_HTTPHEADER])) {
  $existing_headers = $opts[CURLOPT_HTTPHEADER];
  $existing_headers[] = 'Expect:';
  $opts[CURLOPT_HTTPHEADER] = $existing_headers;
} else {
  $opts[CURLOPT_HTTPHEADER] = array('Expect:');
}
curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
$errno = curl_errno($ch);
// CURLE_SSL_CACERT || CURLE_SSL_CACERT_BADFILE
if ($errno == 60 || $errno == 77) {
  self::errorLog('Invalid or no certificate authority found, '.
                 'using bundled information');
  curl_setopt($ch, CURLOPT_CAINFO,
              dirname(__FILE__) . DIRECTORY_SEPARATOR . 'fb_ca_chain_bundle.crt');
  $result = curl_exec($ch); //the line 1003
}
// 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),
    'error' => array(
    'message' => curl_error($ch),
    'type' => 'CurlException',
    ),
  ));
  curl_close($ch);
  throw $e;
}
curl_close($ch);
return $result;
}

首先,请确保使用此代码是否确实配置了cURL扩展。

<?php
echo function_exists('curl_version') ? 1:0; // 1 = enabled , 0 = disabled.

如果已禁用,请要求您的网络托管提供商启用扩展。[我不认为这是一件困难的事情,而不是在他们不知情的情况下玩弄.htaccess和其他启用cURL的手段。]