I have the following problem:
I've made a social network where every user can share his profile on facebook. The user has a ranking on my social network and that ranking must appear in the title of the link shared on facebook. This ranking change basing on user activity: if the user posts anything his ranking grows.
Here comes the first problem: Facebook caches open graph data, so if i share my page for the first time and my ranking is 100, i will have 100 in the title shared on facebook. Then, if my ranking goes up to 200 because i've posted something and i share my page again, i will still see 100 on facebook, because data is cached.
Then i've made the following function:
function refresh(){
$access_token="APPID|APPSECRET"; //replace with your app details
$params = array("id"=>'MY URL', "scrape"=>"true","access_token"=>$access_token);
$ch = curl_init("https://graph.facebook.com");
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_SSL_VERIFYHOST=>false,
CURLOPT_SSL_VERIFYPEER=>false,
CURLOPT_POST=>true,
CURLOPT_POSTFIELDS=>$params
));
$result = curl_exec($ch);
}
Which successfully refreshes the cache.
So, when the user adds a new post a script is called which does as follows:
1) add post to db;
2) refresh();
3) header('location: profile_page');
The problem is the following: refresh() takes long time..so the script to add new post goes from 0.2s (without refresh) to 4s (with refresh) which is annoying for users, because they have to wait long time after having posted and they think my website is slow. Is there a way, in PHP, to execute refresh() in a way that does not let the user wait? Something like:
1) add post to db;
2) run refresh(), but finish the script even if refresh has not finished yet.
3) header('location: profile_page');