Running CURL returns an empty response and shows

I use CURL in my project, it works fine locally, but if I use the same code that it does not execute, I tried to debug it. The output is as follows:

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

I used the following code example:

 $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 the server, I don't know what to include in php.ini.

Please note that CURL and SSL are enabled on the server. If anyone has encountered similar problems, share solutions.

+7
source share
3 answers

PROBLEM:

The curl_exec function curl_exec disabled. What to do?

DECISION:

To resolve this error message, you need to do one of the following things:

  • Remove curl_exec line from disable_functions in php.ini
  • Ask your hosting provider to delete the line above if you do not have access to the php.ini
  • Change the hosting provider to one that allows you to work with the curl_exec function.

Here is an example entry in php.ini .

Edit:

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

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

+4
source

For me in this case, the problem was that I was receiving a 302 redirect, not the actual receive request.

After turning on CURLOPT_VERBOSE from this answer

 $fp = fopen(dirname(__FILE__).'/errorlog.txt', 'w'); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_STDERR, $fp); 

In errorlog.txt I got the following:

 * Connected to www.example.com (XXXX) port 443 (#0) * successfully set certificate verify locations: * CAfile: none CApath: /etc/ssl/certs * SSL connection using ECDHE-RSA-AES128-GCM-SHA256 * Server certificate: * subject: OU=Domain Control Validated; OU=COMODO SSL; CN=www.example.com * start date: 2016-04-28 00:00:00 GMT * expire date: 2018-04-08 23:59:59 GMT * issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA * SSL certificate verify ok. > GET /path/to/file.php HTTP/1.1^M Host: www.example.com^M Accept: */*^M ^M < HTTP/1.1 302 Found^M * Server nginx is not blacklisted < Server: nginx^M < Date: Tue, 20 Sep 2016 02:06:45 GMT^M < Content-Type: text/html^M < Transfer-Encoding: chunked^M < Connection: keep-alive^M < X-Powered-By: PHP/5.5.9-1ubuntu4.19^M < Location: https://www.example.com/other/url/^M < ^M * Connection #0 to host www.example.com left intact 

NB

  • HTTP/1.1 302 Found (there should be only 200 response)
  • Location: https://www.example.com/other/url/ is different from the GET request URL
+7
source

What you can do is check your code below in a live environment to indicate an error

 error_reporting(E_ALL); 

Trying to add a header as requested by you.

For the purpose of debugging.

Php - Debug Twisting

http://www.tuxradar.com/practicalphp/15/10/4

-2
source

All Articles