pixelfederation / doctrine-resettable-em-bundle
Symfony bundle for decorating default entity managers using a resettable decorator.
Installs: 108 106
Dependents: 2
Suggesters: 12
Security: 0
Stars: 17
Watchers: 3
Forks: 7
Open Issues: 0
Type:symfony-bundle
pkg:composer/pixelfederation/doctrine-resettable-em-bundle
Requires
- php: ^8.3
- doctrine/doctrine-bundle: ^2.10
- doctrine/orm: ^2.0
- symfony/config: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/proxy-manager-bridge: ^6.4
- symfony/yaml: ^7.3
Requires (Dev)
- ergebnis/composer-normalize: ^2.48
- friendsofphp/php-cs-fixer: ^3.13.2
- nikic/php-parser: ^5.0
- php-parallel-lint/php-parallel-lint: ^1.3
- phpmd/phpmd: ^2.8
- phpro/grumphp-shim: ^2.10
- phpstan/phpstan: ^2.1
- phpstan/phpstan-webmozart-assert: ^2.0
- phpunit/phpunit: ^12.4
- pixelfederation/coding-standards: ^5.2
- psalm/phar: ^6.13
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^4.0
- symfony/browser-kit: ^7.3
- symfony/flex: ^2.3
- symfony/framework-bundle: ^7.3
- symfony/http-kernel: ^7.3
- symfony/phpunit-bridge: ^7.3
- symplify/config-transformer: ^12.0
- dev-master
- 10.0.0
- 9.0.0
- 8.1.0
- 8.0.0
- 7.0.0
- 6.2.0
- 6.1.0
- 6.0.1
- 6.0.0
- 5.1.0
- 5.0.1
- 5.0.0
- 4.0.0
- 3.0.0
- 2.0.0
- 1.3.9
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-dependabot/composer/doctrine/orm-tw-3.5
- dev-dependabot/composer/symfony/phpunit-bridge-tw-8.0
- dev-update
- dev-dependabot/composer/psalm/phar-tw-6.10
- dev-dependabot/composer/pixelfederation/coding-standards-tw-4.1
- dev-dependabot/composer/doctrine/orm-tw-3.3
- dev-dependabot/composer/phpunit/phpunit-tw-11.5
- dev-fix/composer-and-pipeline
- dev-resettable_doctrine_logger
- dev-test_github_code_navi
This package is auto-updated.
Last update: 2025-12-02 08:19:36 UTC
README
This bundle should be used with workloads where Symfony doesn't get initialized on each request, but stays in memory and the same instance handles multiple requests, one after another (e.g. when using Swoole Bundle). Another use case would be message queue consuming (e.g. Symfony messenger), where it is needed to clear (and possibly reset) the entity manager after processing a message.
The best feature of this bundle is, that it wraps all configured entity managers
into a ResettableEntityManager instance, which
is able to reset the entity manager when it gets stuck on an exception.
After each request the entity manager gets cleared or reset, if an exception occurred during request handling.
Also, another feature is that on each request start the entity manager connection gets pinged, so the connection won't get closed after some period of time.
Instalation
composer require pixelfederation/doctrine-resettable-em-bundle
SETUP
// config/bundles.php return [ //... \PixelFederation\DoctrineResettableEmBundle\PixelFederationDoctrineResettableEmBundle::class => ['all' => true] //... ];
pixel_federation_doctrine_resettable_em: exclude_from_processing: # these entity managers won't be wrapped by the resettable entity manager: entity_managers: - readonly connections: # these dbal connections won't be assigned to the keep alive handler dbal: - readonly # these redis cluster connections won't be assigned to the keep alive handler redis_cluster: - default # default 0 - if set, the connection ping operation will be executed each X seconds # (instead of at the beginning of each request) ping_interval: 10 # default false - if set to true, the app will check if there is an active transaction # in the processed connection, and it will rollback the transaction check_active_transactions: true # for reader writer connections, each has to be defined as 'reader' or 'writer' to be able for the symfony # app to reconnect after db failover. currently only AWS Aurora is supported. failover_connections: default: writer # redis clusters which need to be failed over should be registered here # it's really important to set default timeouts to a low value, e.g. 2 seconds, so the app won't block for too long redis_cluster_connections: default: 'RedisCluster' # connection name (can be literally anything) => redis cluster service id
If you have php-fpm you need only handle RedisCluster on message queue consuming.
So you need to disable Initializers and disable processing for all dbal connections.
pixel_federation_doctrine_resettable_em: disable_request_initializers: true exclude_from_processing: connections: dbal: - default - definition
To enable ping on entity managers during message queue consuming, you can add doctrine_ping_connection middleware: https://symfony.com/doc/current/messenger.html#middleware-for-doctrine