title: Facebook PHP SDK access token randomly expiring, how to seamlessly refresh without load time costs
body: <p>I am using the PHP SDK on my website. I have developed a registration form and login form.</p>
  
  <p>The facebook login link is generated, the user clicks and authorises the app. They are redirected to my site and have an access token.</p>
  
  <p>I can use API call such as $this->facebook->api('/me/');
  I put the call within a try statement and catch any exceptions.</p>
  
  <p>It works perfectly.</p>
  
  <p>The problem is that randomly my access token will expire, as such the api all cannot complete and the exception is caught. I don't know why this is, but what i want to do is seamlessly refresh the access token.. i.e get a new one and continue the users session on the site seamlessly.</p>
  
  <p>What i thus do is save their location in a session, redirect the user to the facebook login page in the catch statement, and then on successfully re-logging in the user redirecting back to where they were.</p>
  
  <p>This works, but there is a problem.
  Having this:</p>
  
  <pre><code>            try
          {
              $me = $CI-&gt;facebook-&gt;api('/me');
          }
              catch(FacebookApiException $e) 
          {               
      //redirect to fb login lin
          }
  </code></pre>
  
  <p>on every page essentially doubles the page load time of every page on the site - the Facebook PHP SDK is inherently slow.</p>
  
  <p>Instead of 1 second page loads, they are taking 2-3 seconds. I have benchmarked it, and it is because of this try/catch..</p>
  
  <p>What can i do? HOw can i maintain/refresh an access key for an authorised user without huge load time costs to my users?</p>