My facebook site app is very slow

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"

Answers


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?


In general you can say that Facebook's API is kind of slow. You should benchmark your page and what takes the most time. But I bet it's the Facebook API call.

Do you really have to download all the pictures? Can't you just use the OpenGraph-URL (https://graph.facebook.com/'.$user_id.'/picture?type=normal) as HTML image tag?

Is there any possibility to make this call asynchronous with AJAX?


Start at the start: debugging the issue. It's quite possible it's just that the Facebook API is slow, which would indeed cause your script to wait until all the resources are loaded, but those results can be cached. Another issue might be that your queries are simply taking too long. Try benchmarking with XDebug to see what the slow parts of your script are, and see if you have the correct indexes for your queries. For example, the second query can possibly be optimised by using a join instead a subquery.


Need Your Help

A simple Relative layout, align to parent right not work

android android-layout android-intent android-emulator android-widget

I have made a simple relative layout which only contains 3 TextView , code is below:

Howto find specifc metadata content and delete it from pictures?

windows command-line exif exiftool

I try to find a specific metadata content like "Odeon" in my *.jpg files with the help of exiftool.exe and then delete this specific tag from the file.