You can use javascript to do this like this:
<?php ... $currentTimeoutInMillis = ini_get('session.gc_maxlifetime') * 1000; print "<script type='text/javascript'>\n"; print "<!--\n"; print "setTimeout('window.location.href=\"timeout.php\"', $currentTimeoutInMillis);\n"; print "//-->\n"; ... ?>
Then your timeout.php will be called automatically when the wait period has expired. In this script, by this time, the contents of $ _SESSION have already been lost (garbage collected) - and you can make your database calls to update the user record.
source share