Reverb
Reverb is a PHP library for executing retry-able transactions with the Doctrine object relational mapper (ORM).
- Install via Composer package icecave/reverb
- Read the API documentation
Overview
Reverb provides functionality similar to Doctrine's EntityManager::transactional()
method, however there are two major differences in the way that exceptions are handled:
- An exception does not cause the entity manager to be closed, instead it is cleared
- The transaction may be retried if the type of exception is considered 'retry safe'
An exception is considered 'retry safe' if any of the following conditions are true:
- It is an instance of Doctrine's OptimisticLockException or PessimisticLockException
- It implements the interface RetrySafeExceptionInterface
- A custom retry safe predicate is provided and it returns
true
when passed the exception
Example
/**
* This is an example of a custom 'retry safe predicate'.
*
* It instructs the transaction executor to retry transactions in the event that
* MyFancyException is thrown.
*
* This same functionality could be accomplished by having MyFancyException
* implement Icecave\Reverb\RetrySafeException.
*/
$isRetrySafe = function (Exception $e) {
return $e instanceof MyFancyException;
};
$executor = new Icecave\Reverb\TransactionExecutor($entityManager, $isRetrySafe);
$result = $executor(
/**
* This is the transaction body.
*
* This function may be called multiple times in order to retry the
* transaction. Each time it is passed the entity manager along with the
* number of attempts remaining, not including this one.
*/
function ($entityManager, $attemptsRemaining) {
// Perform transactional work with $entityManager
return '<result>';
}
);
assert($result === '<result>')
Contact us
- Follow @IcecaveStudios on Twitter
- Visit the Icecave Studios website
- Join
#icecave
on irc.freenode.net