Here is what im doing:
1- Manually authenticate my IS platform to give tokens to OAuth app.
2- I store retrieved details to DB (the return field contains expiry date/time, i store this along the date/time at which tokens are generate)
3- created another file which retrieves token generation date/time and refresh token from DB which was stored in step2 and posts refresh token and other required parameters to IS when 20 hours passed from initial token generation date/time, i run cron command every hour to this file to check 20 hours passed or not, if passed it posts requests to IS.
4- IS post back new tokens with expiration time remaining (its 24 hours at the time of generation) of new token, i add this remaining time to current time when these token were generated and overwrite both in DB
I hope this helps in explaining how i manage to do this and working fine for me. Im having issue using this in PHP code given above.