我有一个帖子的网站,我正在对他们实施Facebook评论。所有帖子将在一个页面中,并在每个“评论(3)”链接下方。点击后,它会转到这篇文章的评论页面,显示Facebook插件。从facebook图形API快速获取信息?
我的问题是,从'评论(3)'获取3需要一段时间...我如何优化这个?这是怎么当的意见是貌似页:https://graph.facebook.com/?ids=http://example.com/
在那里我得到的评论页面,这是我对每一个职位:
echo $postsClass->getCommentsCount($post['id'])
然后这是怎样的getCommentsCount功能看起来像:
public function getCommentsCount($postId) {
$commentsCount = 0;
$url = 'http://myurl.com?post=' . $postId;
$html = file_get_contents('http://graph.facebook.com/?ids=' . $url);
$comments = json_decode($html, true);
if (array_key_exists('comments', $comments[$url])) {
$commentsCount = $comments[$url]['comments'];
}
return $commentsCount;
}
它似乎需要大约3或4秒加载6个职位的意见...任何想法如何改善这一点?
谢谢!
是否确定什么是慢下来了吗?我假设它与Facebook服务器进行通信。有没有一种方法可以预测性地预加载您的评论,无论是在您的页面中,还是在您的服务器上,然后再加载其他评论? –