Memory leak since Debian php update to 5.3.3-7+squeeze16?

hey everyone,

I’m hosting an installation which is tracking approximately 2,500 visits / 8000 views per day. It is hosted on a rather small VPS (2 vCores, 4GB RAM) running Debian Squeeze, apache 2.2.16, php 5.3.3-7+squeeze16 as an apache module and mysql 5.1.66-0+squeeze1. Typical scenario, nothing special at all. Piwik is also the latest version.
Besides piwik there are 30 websites hosted, which get the mentioned visits and are tracked via log-analyrics. This done by piping the apache loglines directly to the import_logs.py script. Stats are build using cron every 10 minutes, browser updating is disabled.

This worked very well until I updated my php a few days ago. I’m not 100% sure if there is a relation since I’m not checking it daily, but many things are indicating this, as i shall explain a few lines below. These are the upgrades made:


Start-Date: 2013-07-21  14:51:40
Commandline: apt-get upgrade
Upgrade: libapache2-mod-php5:amd64 (5.3.3-7+squeeze15, 5.3.3-7+squeeze16), php5-gd:amd64 (5.3.3-7+squeeze15, 5.3.3-7+squeeze16), php5-curl:amd64 (5.3.3-7+squeeze15, 5.3.3-7+squeeze16), libcurl3:amd64 (7.21.0-2.1+squeeze3, 7.21.0-2.1+squeeze4), curl:amd64 (7.21.0-2.1+squeeze3, 7.21.0-2.1+squeeze4), php5-mcrypt:amd64 (5.3.3-7+squeeze15, 5.3.3-7+squeeze16), php5-mysql:amd64 (5.3.3-7+squeeze15, 5.3.3-7+squeeze16), php5-cli:amd64 (5.3.3-7+squeeze15, 5.3.3-7+squeeze16), php5-common:amd64 (5.3.3-7+squeeze15, 5.3.3-7+squeeze16)
End-Date: 2013-07-21  14:51:58

The problem now is, that I can’t use the piwik interface anymore as soon as I’m logged in (no matter which account). My browser (not piwik itself) shows me an error saying that “The connection to the server was reset while the page was loading.” Reloading the page does not work. As soon as I log out by deleting the piwik_auth cookie, I can see the login Screen. But when I log in, the browser error appears again.

I can solve this by restarting the apache server, but only temporarily. At first I can see the stats again, everything seems to work normal. But after some time the problem reappears.
Luckily stats tracking continues to work all the time.

So I took some digging and found the following lines in the apache ErrorLog.


[Wed Jul 24 07:38:16 2013] [error] [client x.x.x.x] PHP Fatal error:  Allowed memory size of 805306368 bytes exhausted (tried to allocate 1973982101 bytes) in /var/www/piwik/libs/Smarty/internals/core.assemble_plugin_filepath.php on line 15
[Wed Jul 24 15:52:15 2013] [error] [client x.x.x.x] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 1629711373 bytes) in /var/www/piwik/libs/Smarty/Smarty.class.php on line 1857
[Thu Jul 25 07:31:27 2013] [error] [client x.x.x.x] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 1724329272 bytes) in /var/www/piwik/core/Menu/Abstract.php on line 85

After these errors appear, piwik isn’t working anymore as explained above. I did not found entries like this dated before my php update, so I suspect a correlation.
Also the amount of memory piwik is trying to allocate seems ridiculously high, ~ 1,5GB. The memory limit for php is 1GB (piwik only, the other webs get much less) and should be more than enough for this amount of data.

The funny thing is I have another VPS, same hoster, same php versions, also hosting piwik and around 80 websites with a similar amout of daily visits and there are no such Problems

Who can help? This drives me mad.

It is possible that Piwik requires (even if only temporarily) more than 1Gb ram (eg. if one of your sites got alot of traffic, or thousands of unique URLs, etc.). First thing is to setup cron: How to Set up Auto-Archiving of Your Reports - Analytics Platform - Matomo

does it help? if not, you will have to increase PHP memory to 2Gb at least temporarily to let archive.php run successfully

matt, thanks for answering. I can imagine you’ve got a lot to do and read …but would you mind reading my first post again?
cron-Archiving ist set up already and working just fine despite the frontend problem. Also I dont think 8000 views is a lot traffic, and I know for a fact that there are not that much unique URLs (50-100 per web I guess). As I said, it worked perfectly fine until last week.

Sure, archiving can use a lot of RAM, but this doesn’t seem to be the problem here. It seems that the Smarty engine has some kind of problem (take a closer look at the 2nd code block above). I’ve never seen an memory error where a process tries to allocate 1,5GB (!) of RAM at once.

Can you try this: Troubleshooting - Analytics Platform - Matomo

No success :frowning:


[Mon Jul 29 08:34:09 2013] [error] [client 217.244.247.150] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 2831293453 bytes) in /var/www/piwik/libs/Smarty/Smarty.class.php on line 1857

2.7 GB …

Can you now try upgrade to Piwik 2 from GIT ? I never heard this bug before, but since it shows up in smarty, we don’t use smarty anymore in Piwik 2, maybe it will fix it?

It’s worth a try. Is it stable enough for a production environment?

Edit: Where can I find it on Github, which is the correct branch ?

It’s not stable yet, but the build passes on travis, so it should mostly work… Branch is master

Are you using suhosin memory settings? I ve seen similar symptoms where the suhosin memory had to be increased even though the php.ini had enough defined.

Suhosin is installed, and I’m using it without customization, so the answer ist probably ‘yes’
… but since I suspected something like that, I disabled it by adding


php_flag suhosin.simulation On

into my VHost-Config. But it didn’t help.

Setup a new directory /piwik2/

Do import from GIT MASTER

copy the config.ini.php from piwik/ to piwik2/config/

then try connnect to /piwik2

(ie. both piwik run in parallel)

does it work better in piwik 2 from git?