Session time if there are no requests (page views) during the timeout. So php solution will not solve the problem.
You need to put a javascript timer on your page, which will be counted from the moment the page is requested and take some action after reaching the threshold (timeout - 5 minutes).
source share