functions.php
Table of Contents
- with_transaction() : void
- Execute a callback within a transaction in the given session
Functions
with_transaction()
Execute a callback within a transaction in the given session
with_transaction(Session $session, callable $callback[, array<string|int, mixed> $transactionOptions = [] ]) : void
This helper takes care of retrying the commit operation or the entire transaction if an error occurs.
If the commit fails because of an UnknownTransactionCommitResult error, the commit is retried without re-invoking the callback. If the commit fails because of a TransientTransactionError, the entire transaction will be retried. In this case, the callback will be invoked again. It is important that the logic inside the callback is idempotent.
In case of failures, the commit or transaction are retried until 120 seconds from the initial call have elapsed. After that, no retries will happen and the helper will throw the last exception received from the driver.
Parameters
- $session : Session
-
A session object as retrieved by Client::startSession
- $callback : callable
-
A callback that will be invoked within the transaction
- $transactionOptions : array<string|int, mixed> = []
-
Additional options that are passed to Session::startTransaction