Reputation: 47
I was just fiddling with php on cloud9 the other day and I can upon this problem that cURL did not seem to be working. When you make a php workspace in cloud9, there is autocomplete for cURL so they must know about it. Here is the code:
<?php
function file_get_data($url){
$ch = curl_init();
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4');
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$data=curl_exec($ch);
curl_close($ch);
return $data;
}
$raw=file_get_data('https://github.com/bower/json/blob/master/package.json') or die('Error Connecting to Resource');
$data=json_decode($raw,true);
echo $data['name'];
?>
The error I a getting in bash is :
Fatal error: Call to undefined function curl_init() in /home/ubuntu/workspace/a.php on line 3
I don't know if this is a problem with my code or a problem with cloud9. Thank you!
Upvotes: 3
Views: 3410
Reputation: 1652
Open a terminal in your cloud 9 enviroment:
First make sure you are running as the master user run this command:
sudo bash
Then run this command to install cURL from command.
apt-get install php5-curl
Then curl_init() should be recognized without issues.
Upvotes: 5
Reputation: 162801
Your php installation doesn't have cURL support. You need to compile php --with-curl=[DIR]
.
-- http://php.net/manual/en/curl.installation.php
Upvotes: 0