Gateway Timeout issue on cron:archive task

Hello,
we wanted to setup the archive cron on one of our clients sites but running into the following error when triggering it manually (to test it’s working):

/path/to/matomo/core/Common.php(271): Notice - unserialize(): Error at offset 0 of 246 bytes - Matomo 3.9.1

Error: Error unserializing the following response from ?module=API&method=API.get&idSite=1&period=week&date=last260&format=php&trigger=archivephp: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>504 Gateway Timeout</title> </head><body> <h1>Gateway Timeout</h1> <p>The gateway did not receive a timely response from the upstream server or application.</p> </body></html>

Wondering what might cause this. Couldn’t find a solution to this problem yet. Since it’s not throwing a ‘mysql is gone away’ notice I suppose it might be caused by something else. This install is hosted on a managed hosting so we cannot change the mysql-conf anyway.

Raising execution times (180 sec) and memory limits (512MB) didn’t help either.

ran the command with
PHP 7.2.3 (cli) (built: Mar 5 2018 11:28:44) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with the ionCube PHP Loader (enabled) + Intrusion Protection from ioncube24.com (unconfigured) v10.2.5, Copyright (c) 2002-2018, by ionCube Ltd.

Can you think of possible causes?

I am also getting this error. Any clues?

@zitrusblau Are you using nginx with php-fpm or a reverse proxy before your Matomo instance?

Hey, thanks.

The site we’re having this issue is hosted on a managed server (L5) (df.eu). So, Apache as a webserver is used. I’m not a server admin so not sure what is the exact setup here and how to find out. I suppose there’s some kind of reverse proxy being used but not sure. The active PHP module is not FPM/FastCGI.

Since we maintain some other sites that are hosted by the same company (even though different hosting plans being involved here) I tried to get the archive cron working on those sites, too. But we’re always runnning into the archive task aborting due to errors.
Now, I did some research and tried to change some php limits directly within the command because I suppose that the configured values in php.ini are only used for the php web module, not the CLI version:

/usr/local/bin/php7-72STABLE-CLI -d memory_limit=1G -d max_execution_time=900 -d max_input_vars=5000 /path/to/matomo/console core:archive --url=https://some.url/matomo/

but still the error persists, no changes. Has anyone further hints on this, maybe?

I am running into the same problem, and I am using php-fpm with NGINX – At the end of the archive I consistently get this message:

INFO [2019-07-19 08:36:17] 20298  Scheduler: finished. Time elapsed: 2.323s
INFO [2019-07-19 08:36:17] 20298  done
INFO [2019-07-19 08:36:17] 20298  ---------------------------
INFO [2019-07-19 08:36:17] 20298  ---------------------------
INFO [2019-07-19 08:36:17] 20298  SUMMARY OF ERRORS
INFO [2019-07-19 08:36:17] 20298  Error: Error unserializing the following response from ?module=API&method=API.get&idSite=1&period=year&date=last1000&format=php&trigger=archivephp: <html>
 <head><title>504 Gateway Time-out</title></head>
 <body>
 <center><h1>504 Gateway Time-out</h1></center>
 <hr><center>nginx/1.16.0</center>
 </body>
 </html>

hope some other users chime in in order to get this issue resolved. of course it might be due to some server configuration/restriction, but which exactly.
would be great if anybody has any more hints on what to check/try instead here.

I also had various issues with timeouts during archive task. Note that Matomo keeps in memory intermediate results, so if you re-launch multiple times it could sucessfully finish at some point (it was my case).

It is documented here: “Once a day/week/month/year is complete and has been processed, it will be cached and not re-processed by Matomo.”