0

I tried the curl sample code from php.net on my local XAMPP V3.2.2 with all default settings, and changed the url to https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json. The curl_exec returns empty string. However when I run the same code on production server, curl_exec returns proper string.

<?php 
// create curl resource 
$ch = curl_init(); 

// set url 
curl_setopt($ch, CURLOPT_URL, "https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json"); 

//return the transfer as a string 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

// $output contains the output string 
$output = curl_exec($ch); 

// close curl resource to free up system resources 
curl_close($ch);     
?>
Don't Panic
  • 13,965
  • 5
  • 32
  • 51
Shiyu
  • 87
  • 6
  • Debug it https://stackoverflow.com/questions/6324819/php-curl-returns-nothing – Devsi Odedra Nov 04 '17 at 09:13
  • are you getting any error? – urfusion Nov 04 '17 at 09:18
  • @urfusion, not getting any error. – Shiyu Nov 04 '17 at 09:32
  • How about `curl_getinfo()`? How about [`CURLOPT_VERBOSE`](https://stackoverflow.com/questions/3757071/php-debugging-curl)? What debugging *have* you tried? – Don't Panic Nov 04 '17 at 10:03
  • @roman reign, by using curl_error($ch), I got "SSL certificate problem: unable to get local issuer certificate", and I guess "https://stackoverflow.com/questions/28858351/php-ssl-certificate-error-unable-to-get-local-issuer-certificate" is the solution, which contains 5 steps to config the xampp. However, in development environment, skip ssl verify, which requires one line of code, it is dirty, but quick and it works. – Shiyu Nov 04 '17 at 12:44

1 Answers1

0

For the local development, to make the curl_exec work, the workaround is add the following line.

    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);
Shiyu
  • 87
  • 6
  • The above code is a quick around, it skips ssl verification and I am ok to use it under development environment. For proper solution, which require to config XAMPP, please refer to https://stackoverflow.com/questions/28858351/php-ssl-certificate-error-unable-to-get-local-issuer-certificate. – Shiyu Nov 04 '17 at 12:45