Cache only /piwik/piwik.php


I’ve configured nginx to cache only /piwik/piwik.php since that file is accessed so frequently. I’m getting “X-Cache: HIT” so I know it’s working. Any suggestions for improvement?

fastcgi_cache_path /var/cache/php-fpm levels=1:2 keys_zone=piwik:10m;

fastcgi_cache_key “$scheme$request_method$host$request_uri”;

location /piwik/piwik.php {
fastcgi_cache piwik;
add_header X-Cache $upstream_cache_status;
fastcgi_pass unix:/run/php-fpm.socket;
include fastcgi.conf;

This page seems to reference a built-in tracker cache:

Is that an alternative to configuring the cache in nginx?

(Matthieu Aubry) #2

Don’t cache this file, this is the tracking API… Tracking HTTP API: API Reference - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3


My system seems to struggle to execute piwik.php at peak times since I switched from mod_php/apache to fastcgi/nginx. Caching piwik.php has alleviated the problem and I still get stats. What do I lose by caching piwik.php?

Is there another tracking method in Piwik that doesn’t require executing PHP with every page access?