Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes)

Hello,

I am getting the following error when viewing the ‘Behavior’ → ‘Pages’ tab. Specifically this happens when viewing a Period “Date Range”. The range to be a prior week (ex: From: Nov28, 2022 - To: Dec 4,2022). This does not happen when Selecting ‘day’, ‘week’, ‘month’ or ‘year’. It only happens when using the ‘date range’ period.



Fatal error : Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /srv/www/matomo/core/DataTable/Row.php on line 361
Matomo encountered an error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) (which lead to: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes))



Any information on what might be happening to where I should investigate would be appreciated.

*I would like to add one update.

I tried clearing the cache through the command using:

sudo ./console cache:clear
[sudo] password for admin-user:

Caches cleared

admin-user@matomo:/srv/www/matomo> sudo ./console cache:clear

Caches cleared


And now the error has changed just slightly:

Fatal error : Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /srv/www/matomo/core/Common.php on line 300
Matomo encountered an error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) (which lead to: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes))

What the logs are saying is that you don’t have enough PHP memory to do the range request. Ranges are not archived in advance and therefore needed to be archived temporarily when you are doing the range request, archiving takes PHP memory, and in this case, you don’t have enough. If you can, try to raise the PHP memory limit.

Thank you for breaking this down for me @Mikke_Schiren. Would you happen to know where to look for the file that I need to make this change?

Hi @Kelsey_jeh
See:

Hi @Kelsey_jeh

Step 1:
For any “Tried to allocate …memory…exhausted” error, determine whether php-fpm or * php-cli was exhausted. Some clues:

  • errors during command line execution are php-cli
  • errors during core:archive for example, are php-cli
  • if the error includes cli=0 in the error message, it is from php-fpm
  • if the error was during an API request, such as requesting data to export to your data tool, or to export a large chunk of Visitors >> Visits Log raw data, it’s php-fpm
  • errors from doing anything in the Matomo interface are php-fpm

Yours is ‘Behavior’ → ‘Pages’ tab. That’s the graphic user interface, so it is the last case, above.

Step 2A, for php-fpm (your case)
The memory setting to fix is in the php-fpm module.

  1. Find the config file location by forcing the Matomo server to serve a file running phpinfo(). Search the result for “config”, to see the config location.

  2. Edit that config file. Double the memory_limit setting. Save.

  3. Please restart
    sudo systemctl restart php{version}-fpm
    for example, in my Ubuntu environment:
    sudo systemctl restart php8.2-fpm

Step 2B, for php-cli (if anyone is reading this and needs CLI instructions!)
(Optional) You can test this ad hoc by executing with the memory_limit in the command:
php -d memory_limit=8G console core:archive

If this error occurred while running php console core:archive you must determine where is the config file for your php-CLI. This is usually different than the file which configures your server PHP. Find the location this way:
php -i | grep "Configuration File"

Then edit that file to increase the memory_limit. You can double it. Many users set this limit for 4G or 8G. Try at the very least 2G.

After you think you set the memory_limit = 4G or at least memory_limit = 2G, check it:
php -i | grep memory_limit

1 Like