CURL execution returns empty response and shows CURL execution returns empty response and shows curl curl

CURL execution returns empty response and shows


For me in this case, the problem was that I was getting a 302 redirect rather than the actual get 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);

I got the following in the errorlog.txt:

* Connected to www.example.com (X.X.X.X) 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.phpHTTP/1.1^MHost: www.example.com^MAccept: */*^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

N.B.

  1. HTTP/1.1 302 Found (should just be a 200 response)
  2. Location: https://www.example.com/other/url/ is different from the GET request URL


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:

  1. Remove the curl_exec string from the disable_functions in the php.ini file
  2. Ask your hosting provider to remove the string above if you don’t have an access to the php.ini file
  3. Change hosting provider to one 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

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