Skip to content

[5.x] Add redisPersistentConnection setting to reuse the Redis connection per PHP process - #371

Merged
snake14 merged 1 commit into
matomo-org:5.x-devfrom
psykologist90:redis-persistent-connection-5x
Nov 16, 2026
Merged

snake14 merged 1 commit into
matomo-org:5.x-devfrom
psykologist90:redis-persistent-connection-5x

Conversation

@psykologist90

Copy link
Copy Markdown
Contributor

Description

Backport of #369 to 5.x-dev, as offered there. It is a cherry-pick of 8e5dc00; the only differences are the version (5.2.3) and the changelog entry.

Adds an opt-in redisPersistentConnection setting. When it is on, the standalone Redis backend connects with phpredis pconnect() instead of connect(), so each PHP-FPM worker keeps one connection open instead of opening a new one on every tracking request.

  • New system setting redisPersistentConnection (bool, default false). Like redisTimeout, it is not exposed in the UI and is set in config.ini.php:
    [QueuedTracking]
    redisPersistentConnection = 1
    
  • Factory wires it up for the standalone backend only. Sentinel and Cluster are unchanged.
  • The persistent id is queuedtracking-<database>, so a client sharing the connection cannot select() another database. This matters when redis.pconnect.pooling_enabled is off; with pooling on (the default) two live clients never share a socket.
  • queuedtracking:test prints the setting as PersistentConnection (standalone Redis only). FAQ entry and changelog added.

Trade-off (also in the FAQ): Redis sees up to pm.max_children connections per web server.

Issue No

Related to #55 (closed by #369 on 6.x-dev)

Steps to Replicate the Issue

  1. Enable the queue with the Redis backend and send N tracking requests.
  2. Expected: Redis connections are reused across requests handled by the same PHP worker.
  3. Actual: Redis INFO stats total_connections_received grows by N.

Checklist

  • [✔] Tested locally or on demo2/demo3? (plugin integration and unit tests against Matomo 5.x-dev on PHP 8.4, MySQL 8.0, Redis 7 + Sentinel: 310 tests, no failures, one intended Sentinel skip; phpcs clean; changed files lint on PHP 7.2)
  • [✔] New test case added/updated? (same tests as Add redisPersistentConnection setting to reuse the Redis connection per PHP process #369: SettingsTest, FactoryTest, RedisTest)
  • [✔] Are all newly added texts included via translation?
  • [NA] Are text sanitized properly?
  • [✔] Version bumped? (5.2.3 in plugin.json and the changelog)
  • [✔] I have understood, reviewed, and tested all AI outputs before use
  • [✔] All AI instructions respect security, IP, and privacy rules
  • [✔] Documentation updated?

🤖 Generated with Claude Code

…er PHP process (matomo-org#369)

* Add redisPersistentConnection setting to reuse the Redis connection per PHP process

Every tracking request opened a new connection to Redis (Queue\Backend\Redis::connect).
With the setting on, the standalone Redis backend uses pconnect, with one persistent id
per database so a client sharing the connection cannot select() another database.
Off by default; configurable in config.ini.php only, like redisTimeout.

Closes matomo-org#55

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Bump to 6.0.5 and assert the persistent connection id in tests

The Factory and database-separation tests passed without the feature. They now
check getPersistentID(), so they fail if the setting is not wired or the database
is missing from the id.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

* Address review: drop the restart caveat, test database separation without pooling

phpredis reconnects a dropped persistent connection by itself, so the FAQ caveat
about a failed first request after a Redis restart did not hold.
With connection pooling on, two clients never share a socket, so the separation
test passed even with a constant persistent id; it now runs with pooling off.
queuedtracking:test marks the setting as standalone Redis only.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

---------

Co-authored-by: Eric Cobos <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 8e5dc00)

@snake14 snake14 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @psykologist90! The changes work as described for Matomo 5. 👍

@snake14
snake14 merged commit 69bd3b8 into matomo-org:5.x-dev Nov 16, 2026
19 checks passed
@psykologist90
psykologist90 deleted the redis-persistent-connection-5x branch November 17, 2026 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants