Reputation: 617
Hi so in my new Facebook application I attempt to load a selection of profile pictures for the users on the screen. The problem is, it just takes way too long. This is what I am currently doing to obtain the pictures - is there anything else I can do to speed this up? It takes ~10seconds+ to execute.
I am using lightbox and only really need the additional pictures to load up once the first image on screen is clicked but not sure how to do that.
//First off we need to get some profile pics for the user:
$getuseralbumsurl = "https://graph.facebook.com/". $row['FB_ID'] ."?fields=albums&access_token="
. $access_token;
$getuseralbums = json_decode(file_get_contents($getuseralbumsurl));
$getuseralbums = $getuseralbums->albums;
foreach( $getuseralbums->data as $album ){//Getting profile pics for user.
if($album->type == "profile"){ //get profile picture album
$albumid = $album->id;
$photosurl = "https://graph.facebook.com/" . $albumid . "/photos?access_token=". $access_token ."&limit=3";
$profilephotos = json_decode(file_get_contents($photosurl));
$counter = 0;
foreach( $profilephotos->data as $image ){
if($counter == 3)//we only want 3 photos from the album.
break;
if($lowerbound == 0)
$photosurlarray['group1'][] = $image->source;
else if($lowerbound == 1)
$photosurlarray['group2'][] = $image->source;
else
$photosurlarray['group3'][] = $image->source;
$counter++;
}
break;//we don't need anymore albums.
}
Thanks!
Upvotes: 0
Views: 503
Reputation: 373
Another way of doing it is to use a cache method via PHP. You'd set it to periodically check every 5 minutes via PHP for the images, then save the resulting HTML to a .txt document or similar. Then you'd simply retrieve the code from the .txt document into your live website. This would guarantee instant loading for any visitor of your website.
Upvotes: 1
Reputation: 617
I ended up solving the issue through using batch requests and spawning the job to run in the background after the page had finished loading (using AJAX). This seems to have done the trick!
Upvotes: 0