I am using a dedicated server.
1gbps port.
There are the following code (which connects with facebook)
if($_POST['friend_id'] != 0) {
$query = "SELECT uid, first_name, pic, sex FROM user WHERE uid = ".$_POST['friend_id'];
}
else {
$query = "SELECT uid, first_name, pic, sex FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me() order by rand() limit 1)";
}
$query = urlencode($query);
$fql_query_url = 'https://graph.facebook.com/'. 'fql?q='.$query. '&access_token=' . $access_token;
$response = $facebook->api("/fql?q=$query");
$data = $response['data'];
Then I use the uid to get the photo of the user.
$img = file_get_contents('https://graph.facebook.com/'.$friend_id.'/picture?type=normal');
$imagesurse1 = $friend_id.uniqid().'.jpg';
file_put_contents($imagesurse1, $img);
$img = file_get_contents('https://graph.facebook.com/'.$user_id.'/picture?type=normal');
$imagesurse2 = $user_id.uniqid().'.jpg';
file_put_contents($imagesurse2, $img);
These code is taking 10 secs to xx seconds. xx reached upto 60.
What could be the problem.
It is a site app. Site doesnot have “https”
Facebook is normally pretty slow. Can’t you cache your results?
Can you test your code piece by piece so you can figure out which part is causing the trouble?