$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:
$facebook->api("/fql?q={$fql}");
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With