Authorising tokens with PHP-SDK

Authorising tokens with PHP-SDK

Hi,

My application uses PHP-SDK to create access tokens, using my refresh token.
Everything works fine but I think it isn't correctly setup. I can authorise and access the CRM and make API calls, but the problem is when I try to make further calls in succession. For example I can successfully create a new quote with no problems. But if I try to create 3 or 4 in a row, I get an OAuth error as shown:

  1. <b>Fatal error</b>:  Uncaught zcrmsdk\oauth\exception\ZohoOAuthException Caused by:'zcrmsdk\oauth\exception\ZohoOAuthException Caused by:'Exception while fetching access token from refresh token
As I understand it, my PHP files must first call:
  1.         $configuration = array(
  2.         'client_id' => 'xxx',
  3.         'client_secret' => 'xxx',
  4.         'redirect_uri' => 'localhost',
  5.         'currentUserEmail' => 'xxx',
  6.         'sandbox' => "true",
  7.         'token_persistence_path' => 'token/');
  8.         ZCRMRestClient::initialize($configuration); 
  9.         
  10.         $oAuthClient = ZohoOAuth::getClientInstance(); 
  11.         $refreshToken = "xxx"; 
  12.         $userIdentifier = "xxx"; 
  13.         $oAuthClient->generateAccessTokenFromRefreshToken($refreshToken,$userIdentifier);
And then each call after this, only needs to call:

  1.         $configuration = array(
  2.         'client_id' => 'xxx',
  3.         'client_secret' => 'xxx',
  4.         'redirect_uri' => 'localhost',
  5.         'currentUserEmail' => 'xxx',
  6.         'sandbox' => "true",
  7.         'token_persistence_path' => 'token/');
  8.         ZCRMRestClient::initialize($configuration); 
At the moment, each of my PHP file's constructor contains the whole lot (i.e. the 13 lines listed above). I think this is the source of my problems, but I am unsure how to correct this.
I believe after the first call, that is the 13 lines listed above, I should from then on only call the 8 lines above as the token will then be saved in a local file.

My question is how do I know when to call the whole constructor (13 lines) as opposed to the shortened version (8 lines)?

I hope this is clear.

For clarity: My application contains about 8 PHP files, each performing some task i.e.: CreateQuote, GetPotentials, UploadAttachment etc. All of these files have the same constructor, the long version (13 lines) and I believe this is not correct. Also, this works fine if I want to take a very small number of actions, but I run into problems when I want to create 2, 3 or 4 quotes in under a minute or so.

Kind regards