Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中每小时仅调用一次Facebook API_Facebook_Facebook Graph Api_Facebook Fql - Fatal编程技术网

在PHP中每小时仅调用一次Facebook API

在PHP中每小时仅调用一次Facebook API,facebook,facebook-graph-api,facebook-fql,Facebook,Facebook Graph Api,Facebook Fql,我正在调用FacebookAPI来检索我在Wordpress博客上的粉丝页面。它工作得很好,我检索了XML并用文件内容解析了它。现在的问题是,API在每次页面加载时都会被调用,同时归档内容是一种相当慢的方法。我希望每小时只调用一次API,并将数据保存在缓存中以减少加载时间 我不知道该怎么办?这可能吗?帮助。这有点低技术,但在文本文件中用时间戳存储类似的内容应该可以。类似这样的方法应该可以在PHP5中使用: $store = 'likes.txt'; // make sure this file

我正在调用FacebookAPI来检索我在Wordpress博客上的粉丝页面。它工作得很好,我检索了XML并用文件内容解析了它。现在的问题是,API在每次页面加载时都会被调用,同时归档内容是一种相当慢的方法。我希望每小时只调用一次API,并将数据保存在缓存中以减少加载时间


我不知道该怎么办?这可能吗?帮助。

这有点低技术,但在文本文件中用时间戳存储类似的内容应该可以。类似这样的方法应该可以在PHP5中使用:

$store = 'likes.txt'; // make sure this file exists, empty is fine to start with

list($likes, $stamp) = explode('|', file_get_contents($store));

if ((time() - $stamp) > 3600){
    // use your own page's name here instead of "php"
    $fbook = json_decode(file_get_contents("https://graph.facebook.com/php"));
    $likes = $fbook->{'likes'};
    file_put_contents($store, "$likes|".time());
}

echo $likes;

这有点低技术,但在文本文件中存储带有时间戳的类似内容应该可以做到这一点。类似这样的方法应该可以在PHP5中使用:

$store = 'likes.txt'; // make sure this file exists, empty is fine to start with

list($likes, $stamp) = explode('|', file_get_contents($store));

if ((time() - $stamp) > 3600){
    // use your own page's name here instead of "php"
    $fbook = json_decode(file_get_contents("https://graph.facebook.com/php"));
    $likes = $fbook->{'likes'};
    file_put_contents($store, "$likes|".time());
}

echo $likes;

什么是真正慢的api调用?不是api,而是file\u get\u contents方法。我知道!但是我只需要知道使文件内容变慢的API调用…我正在调用这个API:什么是真正慢的API调用?不是API,而是文件内容方法。我知道!但我只需要知道使文件内容变慢的API调用…我正在调用此API: