Really Simple PHP CURL and Cache of JSON Result

When using¬†PHP CURL with a¬†third party API, I’ve found keeping the JSON results in a local cache is easier than constantly querying the service – especially when the API is slow or has query restrictions.

Here’s¬†a great snippet I save in my tool belt and use quite often:

If the API is really¬†slow (I’ve encountered two myself) I suggest splitting¬†the snippets CURL+Cache section¬†and putting it¬†into it’s own file, from there create a CRON command to execute the independent CURL+Cache file. That’ll separate the slow API from your PHP app, and your JSON data will still be up to date in the background.


Comments

  1. Thanks David, for the simple solution for a complex issue.. ūüôā

  2. This could not use in flight or hotel search data. there request and response data would be change many time. what should we do there

Leave a Reply

%d bloggers like this: