Iamnewbie Iamnewbie - 2 months ago 20
PHP Question

CURL execution returns empty response and shows

I am using CURL in my project, Its working fine locally but if i use the
same code its not executing, I tried to debug it. The output as follows :

Took 0 seconds to send a request to https://www.google.co.in


I used the following sample code:

$handle=curl_init('https://www.google.co.in');
curl_setopt($handle, CURLOPT_VERBOSE, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
$content = curl_exec($handle);

if(!curl_errno($handle))
{
$info = curl_getinfo($handle);

echo '<br/> Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
}
else
{
echo 'Curl error: ' . curl_error($handle);
}

echo $content;


The Problem is in server, I don't know what to enable in php.ini.

Please note that in server CURL and SSL is enabled. If anyone faced similar problems, share solutions please.

Answer

PROBLEM: Function curl_exec is disabled. What to do?

SOLUTION: In order to eliminate this error message you need to do ONE of the following things: Remove the curl_exec string from the disable_functions at php.ini* file Ask your hosting provider to remove the string above if you don’t have an access to the php.ini* file Change hosting provider which allows the running of the curl_exec function.

Here is an example of the entry in php.ini.

Change from:

disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,show_source,eval,posix_getpwuid

To:

disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,show_source,eval,posix_getpwuid

http://tipstricks.itmatrix.eu/?p=1365

Comments