1

I'm running XAMPP/Win10, PHP 7.0.1. I grabbed Socrata/soda-php from GitHub and ran the index.php. I made no changes to the file.

When I submit the form, I always get Error "0" from server: with no other information. There is nothing in my PHP error logs.

I can access the JSON output directly without problem. I can also grab and parse it with client-side JavaScript.

I reviewed another question with the same problem, but it was a different dataset and so the answer didn't apply. I also checked a suggestion on that question that I enable cURL, which I confirmed.

I am hoping to use this PHP example for accessing data from CMS (which I am already doing with JavaScript), but I need to get it working as-is first so I can teach myself the next steps.

Community
  • 1
  • 1
aardrian
  • 8,581
  • 30
  • 40

1 Answers1

3

To confirm it wasn't a problem in soda-ruby, I did some local testing, and I was able to get the sample working just fine in PHP 7.0.3 (CLI server, freshly installed via homebrew).

The sample code did return zero results, since the dangerous dogs in that location had apparently moved on, so I updated the default location and search range. I also updated the sample to use the new SODA 2.1 endpoint for that dataset, even though the 2.0 version still works just fine for now. So make sure you grab the latest updates just so we're in sync.

The Error "0" message is actually coming from libcurl itself. It means that cURL had an issue even connecting with data.austintexas.gov, which very often means that your system was unable to complete an SSL handshake because PHP/libcurl doesn't trust the certificate of the remote server. I've seen this a number of times with Austin's site, and often with Windows users. I suspect that is the case, especially given that you're able to access the same API via JavaScript.

The solution is to either update your root certificates or point at an external certificate authority that isn't bundled with XAMPP. I've never done that with XAMPP myself, but it seems like a solid answer: Enabling SSL Support for CURL in XAMPP

One of the proposed fixes also disables SSL verification entirely, which would be OK if you were just going to use PHP to hack around a bit and not in production. But please please don't use that workaround in production since it leaves you open to MITM attacks.

chrismetcalf
  • 1,556
  • 1
  • 8
  • 7
  • FYI, I also updated the library to dump out more debugging details when you get a cURL error, should help figure out what is going on there. Make sure you grab the latest version: https://github.com/socrata/soda-php/commit/0a84839d7f2ab0655bb9546cbf3f9aaac8769cd5 – chrismetcalf Feb 16 '16 at 19:44
  • I also added an error check (you may see my fork), which told me the issuer cert was the problem. In the old script adding `curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);` did nothing, but in your update the page now renders. So it looks like now I have to reinstall certs and track down that issue (since nobody likes a MitM), but at least now I have direction. Thanks for the updated script. – aardrian Feb 16 '16 at 22:23
  • Awesome. If you figure out a good way to update the certs in XAMPP, please let me know, since this is bound to come up again. Austin went with some newer SSL provider which is in updated browsers but missing in older OpenSSL CA trust stores. – chrismetcalf Feb 16 '16 at 22:36
  • I added `curl_setopt($handle, CURLOPT_CAINFO, getcwd().'/curl-ca-bundle.crt');` (the path will vary depending on your set-up) using a cert file I grabbed from [the cURL site](http://curl.haxx.se/ca/cacert.pem), which I just renamed and stuffed into the same directory as the PHP files (I also right-click installed it just in case). I disabled the `curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);` and I was good to go. – aardrian Feb 16 '16 at 22:52