Mc Kevin
Mc Kevin

Reputation: 972

enabling curl extension in php for 000webhost.com

So I'm trying to integrate my app with facebook and I'm using the default example.php's code as my index.php. I've changed the appID and appSecret to match my app's id and secret, whenever I test the code on facebook, it will throw an exception namely UnhandledCurlException. Wraping the code with try and catch will only return 0 whenever I call the getUser() method.

I'm aware that I could enable the curl extension on php.ini, but I can only find that on my localhost but not on the server(000webhost.com) which I used to deploy my app.

I've also heard that it's possible to use .htaccess file to explicitly modify the php configurations and hence enable the curl extension, anyone knows how to do that? or are there any other alternatives which I missed?

This is the function that throws error: protected function 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;
}

Upvotes: 2

Views: 2721

Answers (1)

First of all make sure if cURL extension is really configured or not by using this code.

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

If it is disabled, Kindly ask your webhosting provider to enable the extension. [I don't think that's a hard thing to do , instead of playing around .htaccess and other means to enable cURL without their knowledge. ]

Upvotes: 2

Related Questions