On my site users can share theirs reflinks by button. Problem is very slow posting on facebook. My code is following:
if (isset($_GET['error_reason']) && $_GET['error_reason'] == 'user_denied')
{
echo 'You must accept permissions!';
}
else
{
include_once 'src/facebook.php';
$appId = '.............';
$secret = '............';
$returnurl = 'http://site.pl/user/postOnFb.html';
$permissions = 'publish_stream';
//clean cache
$_SESSION['fb_'.$appId.'_user_id'] = '';
$_SESSION['fb_'.$appId.'_access_token'] = '';
$facebook = new Facebook(array('appId'=>$appId, 'secret'=>$secret));
$fbuid = $facebook->getUser();
if ($fbuid)
{
try
{
$status = $facebook->api('/me/feed', 'POST', array('message' => 'TEST'));
if($status)
{
echo 'Post was succesfully published';
}
}
catch (Exception $e)
{
echo 'Error! Try again later.';
}
}
else
{
$fbloginurl = $facebook->getLoginUrl(array('redirect_uri'=>$returnurl, 'scope'=>$permissions));
header('Location: '.$fbloginurl);
}
}
I debugged code and '$facebook->api()' takes about 7 sec. Facebook api is so slow? Or what is wrong?
Edit: I was debugging and I noticed function makeRequest in BaseFacebook is slow:
var_dump(time()); // i add this
$result = curl_exec($ch);
var_dump(time().'</br>'); // i add this
Output:
int(1387198153) int(1387198158) //5 seconds
int(1387198158) int(1387198163) //5 seconds
int(1387198164) int(1387198171) //7 seconds
So problem is with curl_exec()
, but what is wrong?