Facebook FQL -- very slow

$access_token = $facebook->getAccessToken();
$query = "SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me())";
$query = urlencode($query);
$fql_query_url = 'https://graph.facebook.com/'. 'fql?q='.$query. '&access_token=' .    $access_token;
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);

This is the query. It works me faster because I have limited friends. But some app users say that it is very very slow for them if they have about 2000+ friends. They said it took 30 seconds to minutes too.

Why it is very slower? Is there any wrong in this request?


Well, the first thing - as long as you filter users by uid and only select uid after that - the outer query looks redundant. So the final query can be reduced to

SELECT uid2 FROM friend WHERE uid1=me()

The second thing: it is a bit more handy to use fb php sdk to perform FQL queries, not file_get_contents, like:


(taken from https://stackoverflow.com/a/7827550/251311)

It is slower simply because there is more data to be collected. 2000+ friends is quite a lot for a single query...

Some helpful info can be found here - https://developers.facebook.com/live_status.

Other than the live status of the platform (indeed useful to know), there is also two graphs displaying the average API response time and the API error count. If you are noticing extremely slow requests, head over to that link to see if maybe it is a system wide issue.

In my view FQL is good but should be used when regular graph API can't fulfill your requirements. In the given case if the only requirement is to get IDs of friends then you can simply use following code.

FB.api("me/friends?fields=id&limit=3000", function(resp){//process data});

Need Your Help

Client server architecture question

c# .net wcf client-server cluster-analysis

I am working on a client server system, and am running into issues where multiple clients are executing an action at the same time. We are able to solve this by locking on the critical section of c...