Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http function returns nothing and silently fails. CURL error "unable to get local issuer certificate" #5

Open
klabarge opened this issue Mar 2, 2021 · 2 comments

Comments

@klabarge
Copy link

klabarge commented Mar 2, 2021

I'm running PHP on a local IIS stack. After spending more time than I'd like to admit, this was due to my local development environment not having support for SSL.

I hope this helps others out. Cheers! 🍻

Symptom

I was unable to get the http() function to work correctly. It wasn't returning anything. Worse, the function just silently fails.

Note: you can debug cURL using this technique

Resolution

⚠️Caution! You should not make this change in a production environment. Only use it for local development :)

I disabled cURL from verifying SSL by setting these additional options

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
function http($url, $params=false) {
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  if($params)
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
  return json_decode(curl_exec($ch));
}
@rufw91
Copy link

rufw91 commented May 31, 2022

Saved me hours. Thanks

@kimitrii
Copy link

You save my life, thank you so much :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants