Server gone away

I’m on a shared server and have setup and running successfully for over a week now (Matomo 4.x). I have used all the solutions I’m able to from this thread, and still getting emails every hour about the server going away. I set the cronjob to run hourly, and received more emails. I have made the cronjob now run every 12 minutes, and I still get the email every hour. Here is my crontab:

*/12 * * * * /usr/local/bin/php /home/rusername/directory/console core:archive --url=https://statistics.mywebpage.com/ > /dev/null

I cleaned it to remove my username etc. Here is the email I get hourly with the error.

ERROR [2021-04-22 18:12:48] 1983230  /home/username/statistics.webpage/libs/Zend/Db/Statement/Mysqli.php(77): Mysqli prepare error: MySQL server has gone away
Mysqli prepare error: MySQL server has gone away
#0 /home/username/statistics.webpage/libs/Zend/Db/Statement.php(115): Zend_Db_Statement_Mysqli->_prepare('UPDATE `mtnv_op...')
#1 /home/username/statistics.webpage/libs/Zend/Db/Adapter/Mysqli.php(419): Zend_Db_Statement->__construct(Object(Piwik\Db\Adapter\Mysqli), 'UPDATE `mtnv_op...')
#2 /home/username/statistics.webpage/libs/Zend/Db/Adapter/Abstract.php(478): Zend_Db_Adapter_Mysqli->prepare('UPDATE `mtnv_op...')
#3 /home/username/statistics.webpage/core/Db.php(276): Zend_Db_Adapter_Abstract->query('UPDATE `mtnv_op...', Array)
#4 /home/username/statistics.webpage/core/Option.php(198): Piwik\Db::query('UPDATE `mtnv_op...', Array)
#5 /home/username/statistics.webpage/core/Option.php(74): Piwik\Option->setValue('geoip2.loc_db_u...', 'https://downloa...', 0)
#6 /home/username/statistics.webpage/plugins/GeoIp2/GeoIP2AutoUpdater.php(875): Piwik\Option::set('geoip2.loc_db_u...', 'https://downloa...')
#7 /home/username/statistics.webpage/plugins/GeoIp2/GeoIP2AutoUpdater.php(106): Piwik\Plugins\GeoIp2\GeoIP2AutoUpdater->updateDbIpUrlOption('geoip2.loc_db_u...')
#8 [internal function]: Piwik\Plugins\GeoIp2\GeoIP2AutoUpdater->update(NULL)
#9 /home/username/statistics.webpage/core/Scheduler/Scheduler.php(266): call_user_func(Array, NULL)
#10 /home/username/statistics.webpage/core/Scheduler/Scheduler.php(138): Piwik\Scheduler\Scheduler->executeTask(Object(Piwik\Plugins\GeoIp2\GeoIP2AutoUpdater))
#11 /home/username/statistics.webpage/plugins/CoreAdminHome/API.php(69): Piwik\Scheduler\Scheduler->run()
#12 /home/username/statistics.webpage/core/CronArchive.php(627): Piwik\Plugins\CoreAdminHome\API->runScheduledTasks()
#13 /home/username/statistics.webpage/core/CronArchive.php(263): Piwik\CronArchive->runScheduledTasks()
#14 /home/username/statistics.webpage/core/Access.php(664): Piwik\CronArchive->Piwik\{closure}()
#15 /home/username/statistics.webpage/core/CronArchive.php(268): Piwik\Access::doAsSuperUser(Object(Closure))
#16 /home/username/statistics.webpage/plugins/CoreConsole/Commands/CoreArchiver.php(27): Piwik\CronArchive->main()
#17 /home/username/statistics.webpage/vendor/symfony/console/Symfony/Component/Console/Command/Command.php(257): Piwik\Plugins\CoreConsole\Commands\CoreArchiver->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /home/username/statistics.webpage/vendor/symfony/console/Symfony/Component/Console/Application.php(874): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /home/username/statistics.webpage/vendor/symfony/console/Symfony/Component/Console/Application.php(195): Symfony\Component\Console\Application->doRunCommand(Object(Piwik\Plugins\CoreConsole\Commands\CoreArchiver), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 [internal function]: Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /home/username/statistics.webpage/core/Console.php(130): call_user_func(Array, Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /home/username/statistics.webpage/core/Access.php(673): Piwik\Console->Piwik\{closure}()
#23 /home/username/statistics.webpage/core/Console.php(131): Piwik\Access::doAsSuperUser(Object(Closure))
#24 /home/username/statistics.webpage/core/Console.php(82): Piwik\Console->doRunImpl(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /home/username/statistics.webpage/vendor/symfony/console/Symfony/Component/Console/Application.php(126): Piwik\Console->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 /home/username/statistics.webpage/console(32): Symfony\Component\Console\Application->run()
#27 {main}
ERROR [2021-04-22 18:12:48] 1983230  Uncaught exception: /home/username/statistics.webpage/libs/Zend/Db/Statement/Mysqli.php(77): Mysqli prepare error: MySQL server has gone away
Mysqli prepare error: MySQL server has gone away

My PHP.ini file:

allow_url_fopen = Off
display_errors = Off
enable_dl = Off
file_uploads = On
max_execution_time = 120
max_input_time = 120
max_input_vars = 1000
memory_limit = 64M
post_max_size = 16M
session.gc_maxlifetime = 2880
session.save_path = "/var/cpanel/php/sessions/ea-php74"
upload_max_filesize = 8M
zlib.output_compression = Off
mysqli.reconnect = On
mysqlnd.net_read_timeout = 315360000
wait_time = 1800

Any help would greatly be appreciated.

Lastly, one of my 2 web pages being tracked, does have from 70-140+ unique visitors per day. So I guess that is high traffic? I really don’t know what the standard is.

Hi Shane, what MariaDB / MySQL distribution are you using?

When I checked on my cpanel, it shows it as a MySQL database. I honestly am not sure how to check other than that.

While scrolling through the Matomo Settings and diagnostics page, I found this line:

MySQL Version	10.2.37-MariaDB-log

So, I’m not sure what that means.

I’m still getting the emails, though Matomo seems to be working great. I may filter all the emails to the trash. They are that annoying.

Ok, found this info on the System Summary page:

Matomo version: 4.2.1

MySQL version: 10.2.37-MariaDB-log

PHP version: 8.0.3

It looks like the mysql connection is running into a timeout while Matomo tries to update the GeoIP-database. Check if this works (under settings -> system -> geolocalisation). If not, delete the download url and update the DB manually or try to find the reason, why it doesn’t work / takes so long)

I disabled it, and switched to the Default. As you can see in the screenshot, it is working though. Or apparently it is. I will know in an hour… if I get another email or not. When executing the core:archive from the command line, it claims all is fine:

 php console core:archive --url=https://stats.mywebpage.com
INFO [2021-05-10 13:25:46] 557030  ---------------------------
INFO [2021-05-10 13:25:46] 557030  INIT
INFO [2021-05-10 13:25:46] 557030  Running Matomo 4.2.1 as Super User
INFO [2021-05-10 13:25:46] 557030  ---------------------------
INFO [2021-05-10 13:25:46] 557030  NOTES
INFO [2021-05-10 13:25:46] 557030  - Async process archiving supported, using CliMulti.
INFO [2021-05-10 13:25:46] 557030  - Reports for today will be processed at most every 1800 seconds. You can change this value in Matomo UI > Settings > General Settings.
INFO [2021-05-10 13:25:46] 557030  - Archiving was last executed without error 1 min 38s ago
INFO [2021-05-10 13:25:46] 557030  ---------------------------
INFO [2021-05-10 13:25:46] 557030  START
INFO [2021-05-10 13:25:46] 557030  Starting Matomo reports archiving...
INFO [2021-05-10 13:25:46] 557030  Start processing archives for site 1.
INFO [2021-05-10 13:25:46] 557030  Finished archiving for site 1, 0 API requests, Time elapsed: 0.010s [1 / 3 done]
INFO [2021-05-10 13:25:46] 557030  Start processing archives for site 2.
INFO [2021-05-10 13:25:46] 557030    Will invalidate archived reports for today in site ID = 2's timezone (2021-05-10 00:00:00).
INFO [2021-05-10 13:25:46] 557030    Will invalidate archived reports for yesterday in site ID = 2's timezone (2021-05-09 00:00:00).
INFO [2021-05-10 13:25:46] 557030  Finished archiving for site 2, 0 API requests, Time elapsed: 0.005s [2 / 3 done]
INFO [2021-05-10 13:25:46] 557030  Start processing archives for site 3.
INFO [2021-05-10 13:25:46] 557030    Will invalidate archived reports for today in site ID = 3's timezone (2021-05-10 00:00:00).
INFO [2021-05-10 13:25:46] 557030    Will invalidate archived reports for yesterday in site ID = 3's timezone (2021-05-09 00:00:00).
INFO [2021-05-10 13:25:46] 557030  Finished archiving for site 3, 0 API requests, Time elapsed: 0.005s [3 / 3 done]
INFO [2021-05-10 13:25:47] 557030  Done archiving!
INFO [2021-05-10 13:25:47] 557030  ---------------------------
INFO [2021-05-10 13:25:47] 557030  SUMMARY
INFO [2021-05-10 13:25:47] 557030  Processed 0 archives.
INFO [2021-05-10 13:25:47] 557030  Total API requests: 0
INFO [2021-05-10 13:25:47] 557030  done: 0 req, 282 ms, no error
INFO [2021-05-10 13:25:47] 557030  Time elapsed: 0.282s
INFO [2021-05-10 13:25:47] 557030  ---------------------------
INFO [2021-05-10 13:25:47] 557030  SCHEDULED TASKS
INFO [2021-05-10 13:25:47] 557030  Starting Scheduled tasks... 
INFO [2021-05-10 13:25:47] 557030  done
INFO [2021-05-10 13:25:47] 557030  ---------------------------

It also seemed to think that it was fine before I made the change. I have that set to run in a cronjob every 12 minutes.

Thank you for the help! I appreciate any and all help.

Could it be line #20 in the errors I’m getting? How could I find, fix, or address that one?

This seemed to fix it! At least for a good 8 hours I didn’t have a problem. I switched to the Default location tracking too. However after that time, I started getting the emails again. I went in and changed the plugins/GeoIP2 to plugins/GeoIP2.orig Effectively disabling the GeoIP2 plugin. For some reason that was giving me issues. I can live without location data, it isn’t necessary for my analytics.