Hi i am facing a problem regarding php cURL
i am trying to hit a url and getting an xml
which is then converted into an array to display data at somewhere on my website on localhost it works fine but when i put it on cpanel the curl request gets not response and keeps waiting for the response and partially hangs the browser until i restart the browser.i am curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
too but still the problem remains there.
here is my cURL
code
if($is_url) {
if (!($fp = @ fopen($url, 'rb'))) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT,
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/3.0.0.2');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 600);
$contents = curl_exec($ch);
curl_close($ch);
if(!$contents)
return false;
}
while (!feof($fp)) {
$contents .= fread($fp, 8192);
}
fclose($fp);
} else {
$contents = $url;
}
any help regarding this would be really appreciated.Thanks
2
Answers
Since you’re trying to run that on a cPanel server, some php functions might be disabled.
So first thing to do is to check if the php function
allow_url_fopen()
is enable or disabled on the server.Issue a
php -i | grep php.ini
to check which php configuration file is loaded by default (and it’s the default on the server). Then check in that php.ini file and see if allow_url_fopen is On or Off.Depending your cPanel server configuration, a specific cPanel account might be using a totally different php version than the default one on the server.
Also try adding some debugging to your script to see what’s the exact error message. Also you could check the Apache error logs to see if you find any useful information there.
Thank you so much for solving a problem which has been bugging me for DAYS. The major clue was look at the Apache2 log file. Real-Linux-users refer to the logs as a first port of call but those users who do not work with Linux as their main workhorse often forget them.
After checking the apache2 error log I found that PHP was the cause of my problem. Correcting /var/log/apache2/php.ini (or wherever the ACTIVE php.ini file may be) so that
was activated by removing the ; (comment indicator). Problem solved!