I used cURL to get data from another website. Sometimes it shows data and sometimes empty result
Here is my Code
function get_data($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$agent=$_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch,CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$returned_content = get_data('www.example.com');
echo $returned_content;
Curl in PHP returns null on AWS EC2 instance
I had similar issue and I fixed it by making sure versions and settings in php.ini file which is in PHP5 and Apache2 folders were same. If its not then Apache2 tries to execute versions set inside the php.ini settings. Also make sure PHP5-libcurl is installed. Its important too.