Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl returns a null string and curl_error also returns null

Tags:

php

curl

The code i've used is

            $request = 'sales='.$_slots['sales']['value'].'&duration='.$_slots['duration']['value'];
            $ch = curl_init();
            curl_setopt( $ch,CURLOPT_URL, $url );
            curl_setopt( $ch,CURLOPT_POST, 2 );
            curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
            curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
            curl_setopt( $ch,CURLOPT_POSTFIELDS, $request);
            $result = curl_exec($ch );
            $response = explode(chr(10),$result);
            $data = implode('', $response);
            $error = curl_error($ch)
            curl_close( $ch );

The curl_error also returns null so I have no way to track why its not working. The $url is defined above and is a valid url.I also tried without sending any post but still it does not work.

Any advice would be appreciated.Thanks

like image 450
Saeesh Tendulkar Avatar asked May 25 '26 13:05

Saeesh Tendulkar


1 Answers

In my case, curl was only showing this behavior on https URLs, whether CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER are set to false for testing, or not, just as you have here.

I had recently run a yum update which updated Name Service Switch, which was the only change to the server I could think of. I updated via yum on another server, and that server started to show the same failure in curl.

Restarting the Apache service resolved the issue. Https URLs worked in curl after this restart.

I did find examples of curl/ssl/nss errors occurring in the past, but in my case never saw an error message.

  • https://curl.haxx.se/mail/archive-2015-09/0019.html
  • https://unix.stackexchange.com/questions/280548/curl-doesnt-connect-to-https-while-wget-does-nss-error-12286
  • CURL (35) SSL connect error / NSS error -5961

This isn't a very satisfying resolution because I don't feel like I have a full picture of why this failure occurred, so I will continue to investigate and add an update if I find something more.

like image 183
Sean Fahey Avatar answered May 28 '26 04:05

Sean Fahey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!