Download the PHP package facile-it/doctrine-mysql-come-back without Composer
On this page you can find all versions of the php package facile-it/doctrine-mysql-come-back. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download facile-it/doctrine-mysql-come-back
More information about facile-it/doctrine-mysql-come-back
Files in facile-it/doctrine-mysql-come-back
Package doctrine-mysql-come-back
Short Description Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal
License Apache-2.0
Informations about the package doctrine-mysql-come-back
DoctrineMySQLComeBack
This library tries to solve the infamous "MySQL has gone away" issue, and similar ones.
It does so by providing a doctrine/dbal
driver wrapper that automatically reconnects to the database server when applicable; to avoid consistency issues, the reconnection is not attempted when writes are concerned (i.e. open transaction, timeout on write queries).
Installation
If you're using DBAL 4.0+
If you're using DBAL 3.6+
If you're using DBAL ^2.3
Configuration
In order to use DoctrineMySQLComeBack you have to set the wrapperClass
connection parameter.
You can choose how many times Doctrine should be able to reconnect, setting x_reconnect_attempts
driver option. Its value must be an int.
If you're using DBAL v2, you also need to set the driverClass
parameter too; please refer to the previous version of this readme for that.
An example of configuration at connection instantiation time:
An example of yaml configuration on Symfony projects:
An example of configuration on Laminas Framework 2projects:
You can use wrapper class Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Connections\PrimaryReadReplicaConnection
if you are using a primary/replica Doctrine configuration:
Usage
Since DBAL v3, Connection::refresh
does not exist anymore, so you don't need to do anything else to leverage the reconnection, it will be automagically done.
From v1.6
of this library automagically reconnection is enabled also during $em->getConnection()->beginTransaction()
calls,
and this works also during simple $em->flush()
, if out of a previous transaction.
Thanks
Thanks to Dieter Peeters and his proposal on DBAL-275. Check it out if you are using doctrine/dbal <2.3.