Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.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和Twitter API的性能_Php_Performance_Facebook Graph Api_Twitter - Fatal编程技术网

Php Facebook和Twitter API的性能

Php Facebook和Twitter API的性能,php,performance,facebook-graph-api,twitter,Php,Performance,Facebook Graph Api,Twitter,我使用http://urls.api.twitter.com/1/urls/count.json?url=example.com和https://graph.facebook.com/?ids=http://example.com从多个URL中提取like和tweet计数 但是因为我使用这两种方法来获取关于多个URL的数据(最多40个),所以页面加载需要24秒,这是非常巨大的 有没有其他方法可以更快地获取相同的数据(如like和tweet计数) 附言:我正在使用PHP 代码如下: functio

我使用
http://urls.api.twitter.com/1/urls/count.json?url=example.com
https://graph.facebook.com/?ids=http://example.com
从多个URL中提取like和tweet计数

但是因为我使用这两种方法来获取关于多个URL的数据(最多40个),所以页面加载需要24秒,这是非常巨大的

有没有其他方法可以更快地获取相同的数据(如like和tweet计数)

附言:我正在使用PHP

代码如下:

function likes_count($url) {

  $url = urlencode($url);
  $json_string = file_get_contents('http://graph.facebook.com/' . $url);
  $json = json_decode($json_string, true);
  echo "fetching from facebook</br>";
  return intval($json['shares']);

}

function tweets_count($url) {

  $url = urlencode($url);
  $json_string = file_get_contents('http://urls.api.twitter.com/1/urls/count.json?url=' . $url);
  $json = json_decode($json_string, true);
  echo "fetching from twitter</br>";
  return intval($json['count']);

}
函数的计数($url){
$url=urlencode($url);
$json\u string=file\u get\u contents('http://graph.facebook.com/“.$url);
$json=json_解码($json_字符串,true);
echo“从facebook获取”
; 返回intval($json['shares']); } 函数tweets\u count($url){ $url=urlencode($url); $json\u string=file\u get\u contents('http://urls.api.twitter.com/1/urls/count.json?url=“.$url); $json=json_解码($json_字符串,true); echo“从twitter获取”
; 返回intval($json['count']); }
这取决于您的代码。发布代码:done:)我不认为这两个函数是罪魁祸首。实际上,我给他们打了40多次电话(我必须监控的每个链接都打一次电话)。我尝试在没有这些函数的情况下运行代码,速度快了很多。您可以尝试使用ajax将内容逐渐加载到页面中。或者你能在加载资源之前缓存它们吗?不,在这种情况下,Ajax不是一个好主意,因为我需要一次加载所有的社交数据,以便能够根据它们的流行程度对链接进行排序。另一方面,使用缓存是一个好方法。它不允许我进行实时排序,但一个小的延迟并没有那么糟糕。Thx:)