Alish
Alish

Reputation: 240

How can I remove cURL error in GAE google appengine

I'm facing this error in php file Fatal error: Call to undefined function curl_init() when I upload my file on Google appengine gae then I get this error:

I'm trying this cURL in PHP

function getpage($url)
{
// fetch data
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; Android 5.0; ASUS_T00J Build/LRX21V) AppleWebKit/537.36 (KHTML, like Gecko)      Chrome/44.0.2403.133 Mobile Safari/537.36');

$data = curl_exec($curl);
curl_close($curl);
//return preg_replace('~[\r\n]+~', ' ', $data);
return $data;
}

The error is found on this line $curl = curl_init();

How can I remove this error?

Upvotes: 0

Views: 732

Answers (1)

yannik995
yannik995

Reputation: 306

You need to install curl.

Windows: Go to your php.ini file and remove the ; mark from the beginning of the following line:

;extension=php_curl.dll

Ubuntu: ubuntu 13.0 and above, simply use the debundled package. In a terminal type the following to install it and do not forgot to restart server.

sudo apt-get install php5-curl

On GAE:

To Enable cURL_lite

  1. Add the directive google_app_engine.enable_curl_lite = "1" to your php.ini file.

Caveats

  • cURL_lite is only allowed to make calls to HTTP or HTTPS clients
  • cURL_lite didn’t work on my local development server without tweaking runtime to php55, but it works for php in production
  • cURL_lite doesn’t require application to have billing enabled

To Enable cURL

  1. Change your runtime setting in your app.yaml from php to php55.
  2. Add the directive extension = “curl.so” to your php.ini file.

Caveats

  • cURL is only available in App Engine’s PHP 5.5 implementation
  • cURL can only be used by applications that have billing enabled
  • cURL is limited by the restrictions of App Engine’s sockets but include:
    • Limited from targeting Google domains
    • May be reclaimed after 2 minutes of inactivity

Upvotes: 4

Related Questions