My Laravel 5.7 website has been experiencing a few problems
I encountered the same situation on a long-running PHP CLI script (it listens on a Redis list ; each action is quick but the script basically runs for ever).
I create the PDO object and a prepared statement at the beginning, then reuse them afterwards.
The day after I started the script, I got the exact same errors:
PHP Warning: Error while sending STMT_EXECUTE packet. PID=9438 in /...redacted.../myscript.php on line 39
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
In my case, it's a development server, there is no load, MySQL is on the same box... so it's unlikely to come from external factors. It's most likely related to the fact I used the same MySQL connection for too long, and it timed out. And PDO doesn't bother, so any subsequent query will just return "MySQL server has gone away".
Checking the value of "wait_timeout" in MySQL:
mysql> show variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 28800 |
+---------------+-------+
1 row in set (0.06 sec)
mysql> show local variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 28800 |
+---------------+-------+
1 row in set (0.00 sec)
I see 28800 seconds = 8 hours, which seems coherent with the timing of my errors.
In my case, restarting the MySQL server, or setting wait_timeout very low, while keeping the same PHP worker running, makes it very easy to reproduce the issue.
Overall:
To get back to your case