lundi 24 août 2015

Curl in PHP returns null on AWS EC2 instance

I have AWS EC2 , Apache server setup. All website pages are working except for two places whereever I sued CURL. Following pointers as per this issue search online, which are working as expected:

CURL is showing up in phpinfo(). CURL command is accessible and running accross. Apache2 does have CURL installed. curl command from CLI is working fine. (curl http://localhost and curl www.google.com) both are working.

When I ran following function, url when run in browser $url, returns data as expected. But when I run from PHP, none of the echo commands ever returned a values. Further, values seem to be null.

function get_patients(){ $hostname = file_get_contents('http://ift.tt/1hd6V0M'); $url = $hostname.'/folder1/app1.php?all';

//echo $url;

///$url .= urlencode($query);//.'&key='.$key;

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);

//echo $curl;

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT , 400);
curl_setopt($curl, CURLOPT_TIMEOUT, 400);

$data = curl_exec($curl);

curl_close($curl);

//decoding request

$result = json_decode($data, true);

//print_r( $data);

return $result;

}

This is the first function, based on which most of APIs are dependent on. This above php file is in var/www/html/folder1. when I access the main API that I am trying to access in browser, $hostname.'/folder1/app1.php?all', does return data as hosted on a local apache server and even remote domain host server as well. Its just not working with AWS EC2. Any help will be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire