MySQL server has gone away. Error Code 2006

On the flip side, I license my software by the number of concurrent users, so keeping the database connection active allows me to count the number of active users when the next one tries to log in.

You can track connections in the database itself without maintaining active connections. Create a table to track connections. When a user logs in, add the username, time/date of login, and time of last transaction. When they log out, you remove the record from the table.

You can then query the number of records of “logged in” users and report a licensing issue if the count exceeds a given value. I tend to clear out the table if the connection if the user has been idle more than 8 hours (normal 8 hour work day). If the user tries an action and there is no “logged in” record for the user, they are forced to login to the app again.