title: "MySQL server has gone away" followed by "Got a packet bigger than 'max_allowed_packet' bytes"
body: <p>A lot of people ask about this, but none of the previous answers solved my issue.</p>
  
  <p>I'm running a CakePHP web app and every so often I get 2 errors in succession:</p>
  
  <p><code>MySQL server has gone away in [/var/www/html/vendor/cakephp/cakephp/src/Database/Driver/PDODriverTrait.php, line 159]</code></p>
  
  <p>followed by </p>
  
  <p><code>SQLSTATE[08S01]: Communication link failure: 1153 Got a packet bigger than 'max_allowed_packet' bytes</code></p>
  
  <p>This happens when a new record is attempted to be inserted into the DB.</p>
  
  <p>After the errors the database connection still seems to be working as PHP can still read from it, but ANY new <code>INSERT</code> into the database results in another <code>Got a packet bigger than 'max_allowed_packet' bytes</code> error. The only solution at that point is to restart mySQL or the error will show up on every other <code>INSERT</code> forever.</p>
  
  <p><strong>I have already set max_allowed_packet = 512M in my.cnf as suggested and that didn't solve the problem.</strong></p>
  
  <p>I refuse to believe that someone is sending a packet larger than 512MB! Am I missing something? Is there some cache or queue somewhere which every so often just fills up that a restart clears and makes everything work fine again?</p>