Retrieve JSON file from the source and put it into the directory and make it updated periodically with PHP

I’m using WordPress and use the API data with JSON format from a source for my site content, for example: http://api.source.com/data.json

But loading of my site take a bit longer because every time the page loaded will always take and read the file from the source, the question is how can I store the JSON file to WordPress directory and automatically update it every 12 hours?

Read More

Sorry for bad English but hope you got my point, Please help!

Related posts

Leave a Reply

1 comment

  1. There are multiple options.

    1. Use memcache -> Store the retreived json in memcache, and expire it after every 12 hours. This would be the fastest lookup.
      http://www.php.net/manual/en/memcache.examples-overview.php

    2. Database -> Store the retreived json in a database table with a key, you can use varchar , text , or blob datatype based on size of your json.

    3. Write to a file -> Write the json to a text file in any of your directory which has write permissions,and read it from there.
      http://php.net/manual/en/function.file-put-contents.php