My application has a single index.php
Main things it does are
1. Uses facebook login to let the user login to my application. (In future I will use additional sites like google etc for login etc)
2. Does the “Main work”
3. Displays the result.
Main work:
1. Gets an access token from fb. – Takes <10 ms
2. Gets data set 1 – Uses accesstoken and gets data about the user. – Takes about a second.
3. Gets data set 2 – Spiders each of the friend in the list for partiuclar information – Takes about a second for each friend. So, takes around 300 seconds on average.
4. Does some processing – Few Seconds
Problem Areas
1. Step 3 exceeds Max_Execution_Time always.
Solution constraints
1. Wish to stick with php only. No Python/ruby.
My code skeleton is :
<?php
// Login
$facebook->getloginurl ......
//Main work
$access_token = $facebook-> ......
$user_id = $facebok->get ......
// Following is the time consuming step
foreach $friend_of_that_user .... get information required for this app.
//Displays result
echo ""
?>
You are making a single request for each friend! this can be enhanced by one of the following methods:
Field Expansion:
Getting the name and 5 movies of the first 100 friends:
Batch API:
For example, to get the details of 5 of your friends, you can issue the following Batch request:
Now I would really recommend considering pagination instead of removing the
limitfield all together. If pagination is relevant to your app, it could enhance the experience A LOT!