How to release mySQL connection after a specific period of time

The option $_SESSION is fantastic for security but I’m not sure how to apply this to release mySQL connection after a predefined period of time, especially if there is no user activity. From what I can gather the $_SESSION (as demonstrated in https://www.youtube.com/watch?v=bpR7BTI8n4s&list=PLDMYt0EmYW5xKNVdQ8s16L_eyCp3hNoU6 ) does not release mysql resources until the user tries to do something. Can someone please advise me here.