I use Facebook Graph API to fetch my Facebook Fans pages ( 7 Facebook pages in total ) with the following codes :
<?php
header('Content-Type: text/plain; charset=utf-8');
require_once('facebook.php');
$facebook = new Facebook(array(
'appId' => 'MY_APP_ID',
'secret' => 'MY_APP_SECRET',
));
$page_feed_1 = $facebook->api('MY_FB_PAGE_ID_1/feed');
$page_feed_2 = $facebook->api('MY_FB_PAGE_ID_2/feed');
// ... etc
?>
I plan to cache the JSON result to file and the output page ( which displays the contents of the Facebook pages ) loads from the cache files. But what should my loading sequence if I can't use cron job ( yes, my web server is Linux-based ) ?
My current plan is :
- When the output page loads, check for cache file, if yes, load the cache file
- Use a deferred JavaScript to create an AJAX call to a PHP script to fetch updated contents from Facebook and save to cache file
The problem I can now think of is, when many users visit the output page, the cache will refresh many times. How can I check the last update time of my Facebook page? If the content is the same, the cache won't refresh.
Note: My question is not about parsing JSON / Array in PHP.