I have AWS EC2 setting up an Apache server. All pages of the website work, with the exception of two places where I sued CURL. The following pointers, in accordance with this problem, look for online that work as expected:
CURL is displayed in phpinfo (). The CURL team is available and works in different ways. Apache2 has CURL installed. the curl command from the CLI is working fine. (curl http: // localhost and curl www.google.com) both work.
When I ran the following function, url when launched in the browser, $ url returns the data as expected. But when I run from PHP, none of the echo commands ever returned a value. In addition, the values seem to be zero.
function get_patients () {$ hostname = file_get_contents (' http://169.254.169.254/latest/meta-data/public-hostname '); $ 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 feature that most APIs are based on. This above php file is in the var / www / html / folder1 file. when I access the main API I'm trying to access in a browser, $ hostname. '/folder1/app1.php? all ' , returns data as hosted on the local Apache server and even the remote domain. Its just not working with AWS EC2.