Download the PHP package geonative/garbage-collector without Composer
On this page you can find all versions of the php package geonative/garbage-collector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download geonative/garbage-collector
More information about geonative/garbage-collector
Files in geonative/garbage-collector
Package garbage-collector
Short Description Doctrine Entities garbage collector
License MIT
Informations about the package garbage-collector
Doctrine Garbage Collector
This package is a Symfony Bundle providing a "garbage collector" command to prune Doctrine entities that you consider stale.
Installation
PHP 8.4 or above is required.
Configuration
-
Add the bundle into your
config/bundles.php(likely to be done automatically with Symfony Flex). -
Update your configuration:
-
Update your database schema:
- Implement
GeoNative\GarbageCollector\PrunableRepositoryInterfaceon your repositories:getGarbageCollectorCheckInterval()should return the minimum interval between checks, to avoid ruining your DB performancespruneStaleEntities()should actually perform removals and return the number of entities which have been removed.
If your entities should be pruned against a DateTime column, you can use GeoNative\GarbageCollector\PruneStaleEntitiesTrait to get started faster.
The trait deletes the stale entities in batches of 1 000: it reads the identifiers of the oldest stale entities
on the date column's index, then deletes them by identifier, so that each DELETE locks only the rows it removes.
Index that column, and override getPruneBatchSize() to change the batch size. Keep it well below 9 000 on MySQL:
a longer list of identifiers exceeds the default range_optimizer_max_mem_size and the DELETE falls back to a
full table scan.
Usage
Oneshot
You can store this in a crontab to periodically cleanup your entities.
Daemonize
This command can also run in a loop and be daemonized with supervisord or systemctl.
The react/event-loop package is required.
The Garbage Collector will pass every 5 seconds.
Before pruning a class, the Garbage Collector checks the connection of the entity manager owning it, and reconnects it if the server has dropped it. A repository checked only once in a while leaves its connection idle in between, long enough for the server to close it: without that check, the first statement of the next prune would fail in a long-running loop.
Lock
If your application runs on multiple hosts, you may want to prevent several instances
of the Garbage Collector from running simultaneously. To do so, just add a --lock option:
Tests
License
MIT.
All versions of garbage-collector with dependencies
symfony/http-kernel Version ^7.4 || ^8.0
symfony/console Version ^7.4 || ^8.0
doctrine/doctrine-bundle Version ^3.2
doctrine/orm Version ^3.6
symfony/uid Version ^7.4 || ^8.0