Search by

marciopaiva / infinispan-symfony

marciopaiva

Symfony cache adapter, session handler and lock store, with a bundle, for Infinispan through the infinispan PHP extension

Package info

github.com/marciopaiva/infinispan-symfony

Type:symfony-bundle

pkg:composer/marciopaiva/infinispan-symfony

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-12-06 06:53 UTC

This package is auto-updated.

Last update: 2026-12-06 10:30:17 UTC


README

A Symfony cache adapter, session handler and lock store for Infinispan and Red Hat Data Grid, with a bundle that wires them. It talks Hot Rod, Infinispan's binary protocol, through the infinispan PHP extension, which keeps one connection per PHP process: a PHP-FPM worker connects once and reuses it for every request.

Status: 0.1, early. Symfony 7.4 and 8, PHP 8.2 to 8.5, Linux, with the infinispan extension 0.3.

Install

The extension comes first. PIE 1.6 or newer installs a prebuilt binary (x86_64 and arm64, glibc 2.36+ or musl):

pie install marciopaiva/infinispan-php

Then the bundle:

composer require marciopaiva/infinispan-symfony

The bundle has no Flex recipe yet, so add it to config/bundles.php:

Infinispan\Symfony\InfinispanBundle::class => ['all' => true],

The server needs the caches the services use, symfony-cache, symfony-sessions and symfony-locks by default. Once the connection is configured (below), create the missing ones:

php bin/console infinispan:caches

It creates each missing cache as a distributed cache, or with infinispan.cache_configuration (XML, JSON or YAML), and leaves existing ones alone. --volatile keeps them out of the server's configuration, so a restart removes them. The user needs the server's admin permission. Caches can also be defined in the server's own configuration instead.

Configure

config/packages/infinispan.yaml:

infinispan:
    servers: '%env(INFINISPAN_SERVERS)%'     # host:port, separated by commas
    username: '%env(INFINISPAN_USERNAME)%'   # leave out to skip authentication
    password: '%env(INFINISPAN_PASSWORD)%'

framework:
    cache:
        app: cache.adapter.infinispan
    session:
        handler_id: infinispan.session.handler

Locks need no framework setting. framework.lock takes only connections it knows, not a ready-made store, so the bundle provides infinispan.lock.factory and makes it the application's default LockFactory, in place of FrameworkBundle's local flock store. Set infinispan.lock.replace_default: false to keep FrameworkBundle's.

Every option, with its default:

infinispan:
    servers: '127.0.0.1:11222'
    username: ~
    password: ~
    sasl_mechanism: SCRAM-SHA-512   # or DIGEST-SHA-256, or PLAIN (only over TLS)
    tls:
        enabled: false
        server_name: ~              # the first server's host
        ca_file: ~                  # the system trust store when not set
        cert_file: ~                # with key_file, for mutual TLS
        key_file: ~
    timeout: 5                      # seconds, for connecting and each operation
    max_retries: ~                  # the client's default when not set
    caches:
        cache: symfony-cache
        sessions: symfony-sessions
        locks: symfony-locks
    cache_configuration: '<distributed-cache>...</distributed-cache>'   # for infinispan:caches
    session:
        prefix: ''
        ttl: ~                      # seconds; session.gc_maxlifetime when not set
    lock:
        initial_ttl: 300
        replace_default: true       # infinispan.lock.factory becomes the LockFactory

Any value can be an %env()% placeholder; the client is built from them when it is first used, not when the container is compiled.

What it does

  • Cache adapter. cache.adapter.infinispan works for cache.app and for any pool. Values go through Symfony's marshaller. Namespaces are versioned, as with the Memcached adapter: clearing a pool, for example with cache:pool:clear, switches it to a new version, and the old entries stay on the server until they expire. Give pools a default_lifetime, or the Infinispan cache an expiration or size limit, if they are cleared often. Tags work through Symfony's TagAwareAdapter. A pool can use another Infinispan cache by naming an Infinispan\Cache service as its provider:

    services:
        infinispan.cache.reports:
            class: Infinispan\Cache
            factory: ['@infinispan.client', 'cache']
            arguments: ['reports']
    
    framework:
        cache:
            pools:
                cache.reports:
                    adapter: cache.adapter.infinispan
                    provider: infinispan.cache.reports
  • Sessions. One entry per session, expiring after the TTL. The server removes expired sessions, so garbage collection does nothing.

  • Locks. Acquiring is one putIfAbsent. Refreshing and releasing check the lock's token and write only if the entry is unchanged, so a process whose lock expired never extends or releases the lock another process holds now.

The classes need no bundle. With the extension alone:

$client = new Infinispan\Client(['servers' => 'cache.internal:11222']);
$pool = new Infinispan\Symfony\Cache\InfinispanAdapter($client->cache('app'), 'app');
$store = new Infinispan\Symfony\Lock\InfinispanStore($client->cache('locks'));

Failures are the extension's exceptions, such as Infinispan\ConnectionException. The client connects when the first service that needs it is created, so an unreachable server throws there. After that, the cache adapter logs and swallows failed operations, as Symfony's own adapters do, while the session handler and the lock store let them through.

Tests

Unit tests need the extension but no server:

composer install
vendor/bin/phpunit --testsuite unit

Live tests need Docker for the server:

ci/infinispan/setup.sh
INFINISPAN_LIVE=1 INFINISPAN_USERNAME=testuser INFINISPAN_PASSWORD=testpass \
  vendor/bin/phpunit --testsuite live
ci/infinispan/teardown.sh

ci/app/smoke.sh creates a fresh Symfony application with the bundle and checks the cache, session and lock over HTTP.

License

Licensed under either of Apache License, Version 2.0 or MIT license, at your option.