Problem: I was trying to make a mysql query after a function, that was taking a lot of time to load, and my query was not being executed. In addition I was receiving the error: “MySQL server has gone away”. This was caused because the mysql server was timed out and closed the connection.
The solution in this case was to ping the server and check if there is any active connection otherwise try to reconnect.
if (!$mysqli->ping()) $db = new mysqli($host, $username, $password, $dbname, (int)$port, $socket);
The default behavior for ping() is to try and reconnect automatically, but in my case it didn’t work out.