EDIT: In my opinion is this not a duplicate because non of the mentioned answers are solving the problem.
We have running a MariaDB 10.3. on a Synology-Server and almost everything works fine. But after a certain number of queries within one PHP-connection (mysqli) the server isn't reacting any more so PHP throws after a while 2006 server has gone away.
The number of queries until the error raises depends on the query. To example "SELECT RAND()" within a PHP-loop gives 3714 results and then the error, "SELECT RAND() * $i" (with $i the PHP-loop-index) gives 2718 results and than the error, both examples are reproducible and regardless any build-in PHP-loop-delay or the server-load. For real-live complex queries this number until the error raises reduce to something between 100 and 200 queries, that's the problem.
All the buffer- and timing-settings seems to be OK. To example wait_timeout = 28800, interactive_timeout = 28800 and max_allowed_packed = 128M.
I have searching stackoverflow and the internet with no results and also asking the Synology service with no result and i didn't find any related system-variable in the mySql- or MariaDB-documention.
To close the PHP-connection and open a new PHP-connection after each query (or after N queries) is a possible work-a-round until you need the last_insert_id or you use transactions or you have to update hundreds of records. we need all of this.