Coder Social home page Coder Social logo

Comments (3)

dejanstojanovic avatar dejanstojanovic commented on June 20, 2024

You can build a tiny proxy and cache your responses from the Facebook Graph API. This way you will only have non cached requests going out to Facebook to fetch new data.
Cache on the proxy can be set to 24h so you always get fresh data with maximum one day of delay, but I guess you do not upload your photos often than that.

from facebook-album-browser.

aethatsme avatar aethatsme commented on June 20, 2024

would something like this work?

function get_data($url) {
/** @var $cache_file is path/to/the/cache/file/based/on/md5/url /
$cache_file = 'cache' . DIRECTORY_SEPARATOR . md5($url);
if(file_exists($cache_file)){
/
*
* Using the last modification date of the cache file to check its validity
/
if(filectime($cache_file) < strtotime('-60 minutes')){
unlink($cache_file);
} else {
echo 'TRACE -- REMOVE ME -- out of cache';
/
*
* unserializing the object on the cache file
* so it gets is original "shape" : object, array, ...
*/
return unserialize(file_get_contents($cache_file));
}
}

$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);

/** 
 * We actually did the curl call so we need to (re)create the cache file 
 * with the string representation of our curl return we got from serialize 
 */
file_put_contents($cache_file, serialize($data));

return $data;

}

from facebook-album-browser.

dejanstojanovic avatar dejanstojanovic commented on June 20, 2024

This looks like PHP to me. Not a great expert with it, but I guess this is one way to do it by saving it to the file.

from facebook-album-browser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.