Facebook PHP Graph SDK performance issue -


i'm using facebook php sdk v5 simple task: converting javascript short-lived user token long lived 1 , returning it.

the issue i'm having requests seem take long time when issued sdk compared postman or graph api explorer.

in order benchmark have used profiling calls, i'm measuring both high level execution times , lowest level possible (wrapping curl call) make sure issue not related additional php overhead.

$fb = new facebook\facebook([   'app_id' => $options['app_id'],   'app_secret' => $options['app_secret'],   'default_graph_version' => 'v2.10',   ]);  $helper = $fb->getjavascripthelper(); $prev = performancelog($prev, 'fbinit'); try {     $accesstoken = $helper->getaccesstoken(); } catch (\facebook\exceptions\facebookresponseexception $e) {     // when graph returns error     die(500);  } catch (\facebook\exceptions\facebooksdkexception $e) {     // when validation fails or other local issues     die(500); } $prev = performancelog($prev, 'gettoken'); if (!isset($accesstoken)) {     if ($helper->geterror())     {         die(var_dump($helper->geterror()));     } else {         die(500);     } } else {     // oauth 2.0 client handler helps manage access tokens     $oauth2client = $fb->getoauth2client();      // access token metadata /debug_token     $tokenmetadata = $oauth2client->debugtoken($accesstoken);      // validation (these throw facebooksdkexception's when fail)     $tokenmetadata->validateappid($options['app_id']);     // if know user id access token belongs to, can validate here     $tokenmetadata->validateexpiration();     $prev = performancelog($prev, 'validation');     if (!$accesstoken->islonglived()) {         // exchanges short-lived access token long-lived 1         try {             $accesstoken = $oauth2client->getlonglivedaccesstoken($accesstoken);         } catch (\facebook\exceptions\facebooksdkexception $e) {             die(var_dump($e));         }     }     $prev = performancelog($prev, 'getlong');     echo $accesstoken->getvalue();     $prev = performancelog($prev, 'echogetvalue'); } 

which standard, profiling times are:

init : 0.15900301933289   fbinit : 0.0040819644927979   gettoken : 1.5706379413605 of request : 1.566477060318   validation : 1.5675730705261 of request : 1.5646359920502   getlong : 0.56497001647949 of request : 0.56240797042847  echogetvalue : 4.0531158447266e-6 

am doing wrong? there other solution besided caching? keep in mind times variable: go 3 seconds around 12, times out.

thanks


Comments