Recently, we ran into a bizarre issue with a Drupal7 installation that we work on, but don’t fully control. A module was pulling a remote JSON API and presenting it inside the drupal application. To retrieve the API, we were using drupal_http_request. Things were fine until the response of the API grew in size. (And not to a large size. The issue appeared when there were about 15 records returned.) At this point, all of the JSON wasn’t returned by the http request. Then, the text that was available wasn’t valid JSON, and the information display failed. This issue only appeared on the staging and production systems, which made debugging difficult.
After some troubleshooting, the best fix was determined to be a workaround. Rather than continuing to use drupal_http_request, the code was modified to use the php function curl_exec. This didn’t have issues in the remote environments, and all the JSON was retrieved, even for the problematic large requests.
There are a couple of takeaways from this experience.
- Sometimes the perfect is the enemy of the good. Yes, it would have been preferable to solve the issue at the root level and continue to use the drupal API. But the workaround was just as effective in solving the problem and more time efficient.
- Software is more than just the code you write. The environment in which it executes fundamentally affects the software, often in subtle ways.
- You should have a staging system that is as close as possible to your production system in every way. Without that, some issues will simply have to be debugged on your production systems, which is not kind to your reputation nor to your users.