2017 © Pedro Peláez
 

library doctrine-mysql-come-back

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

image

facile-it/doctrine-mysql-come-back

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  • Friday, April 20, 2018
  • by peelandsee
  • Repository
  • 40 Watchers
  • 96 Stars
  • 291,283 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 24 Forks
  • 3 Open issues
  • 16 Versions
  • 13 % Grown

The README.md

Latest Stable Version Latest Unstable Version Total Downloads, (*1)

Build status Test coverage License, (*2)

DoctrineMySQLComeBack

This library tries to solve the infamous "MySQL has gone away" issue, and similar ones., (*3)

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)., (*4)

Installation

If you're using DBAL 3.6+, (*5)

$ composer require facile-it/doctrine-mysql-come-back ^2.0

If you're using DBAL ^2.3, (*6)

$ composer require facile-it/doctrine-mysql-come-back ^1.0

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., (*7)

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., (*8)

An example of configuration at connection instantiation time:, (*9)

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;

$config = new Configuration();

//..

$connectionParams = [
    'dbname' => 'mydb',
    'user' => 'user',
    'password' => 'secret',
    'host' => 'localhost',
    // [doctrine-mysql-come-back] settings
    'wrapperClass' => 'Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Connection',
    'driverOptions' => [
        'x_reconnect_attempts' => 3
    ],
];

$conn = DriverManager::getConnection($connectionParams, $config);

//..

An example of yaml configuration on Symfony projects:, (*10)

doctrine:
    dbal:
        connections:
            default:
                # DATABASE_URL would be of "mysql://db_user:db_password@127.0.0.1:3306/db_name" 
                url: '%env(resolve:DATABASE_URL)%'
                wrapper_class: 'Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Connection'
                options:
                    x_reconnect_attempts: 3

An example of configuration on Laminas Framework 2projects:, (*11)

return [
    'doctrine' => [
        'connection' => [
            'orm_default' => [
                'wrapperClass' => \Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Connection::class,
                'params' => [
                    'host' => 'localhost',
                    'port' => '3307',
                    'user' => '##user##',
                    'password' => '##password##',
                    'dbname' => '##database##',
                    'charset' => 'UTF8',
                    'driverOptions' => [
                        'x_reconnect_attempts' => 9,
                    ]
                ],
            ],
        ],
    ],
];

You can use wrapper class Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Connections\PrimaryReadReplicaConnection if you are using a primary/replica Doctrine configuration:, (*12)

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;

$config = new Configuration();

//..

$connectionParams = [
    'wrapperClass' => 'Facile\DoctrineMySQLComeBack\Doctrine\DBAL\PrimaryReadReplicaConnection',
    'primary' => [
        // ...
        'driverOptions' => [
            'x_reconnect_attempts' => 3
        ],
    ],   
];

$conn = DriverManager::getConnection($connectionParams, $config);

//..

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., (*13)

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., (*14)

Thanks

Thanks to Dieter Peeters and his proposal on DBAL-275. Check it out if you are using doctrine/dbal <2.3., (*15)

The Versions

20/04 2018

dev-master

9999999-dev

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  Sources   Download

Apache-2.0 Apache License Version 2.0

The Requires

 

The Development Requires

by luca bo

doctrine exception mysql connection refresh reconnect has gone away

20/04 2018

v1.6.5

1.6.5.0

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

by luca bo

doctrine exception mysql connection refresh reconnect has gone away

01/09 2017

v1.6.4

1.6.4.0

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by luca bo

doctrine exception mysql connection refresh reconnect has gone away

27/07 2017

dev-dbal_2.6_compat

dev-dbal_2.6_compat

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by luca bo

doctrine exception mysql connection refresh reconnect has gone away

18/05 2017

dev-drop_older_deps

dev-drop_older_deps

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by luca bo

doctrine exception mysql connection refresh reconnect has gone away

30/09 2016

v1.6.3

1.6.3.0

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  Sources   Download

Apache License Version 2.0

The Requires

 

The Development Requires

by luca bo

doctrine exception mysql connection refresh reconnect has gone away

03/06 2016

v1.6.2

1.6.2.0

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  Sources   Download

Apache License Version 2.0

The Requires

 

by luca bo

doctrine exception mysql connection refresh reconnect has gone away

16/05 2016

v1.6.1

1.6.1.0

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  Sources   Download

Apache License Version 2.0

The Requires

 

by luca bo

doctrine exception mysql connection refresh reconnect has gone away

26/11 2015

v1.6

1.6.0.0

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  Sources   Download

Apache License Version 2.0

The Requires

 

by luca bo

doctrine exception mysql connection refresh reconnect has gone away

10/11 2015

v1.5.3

1.5.3.0

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  Sources   Download

Apache License Version 2.0

The Requires

 

by luca bo

doctrine exception mysql connection refresh reconnect has gone away

02/04 2015

v1.5.1

1.5.1.0

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  Sources   Download

Apache License Version 2.0

The Requires

 

by luca bo

doctrine exception mysql connection refresh reconnect has gone away

02/04 2015

v1.5.2

1.5.2.0

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  Sources   Download

Apache License Version 2.0

The Requires

 

by luca bo

doctrine exception mysql connection refresh reconnect has gone away

27/02 2015

v1.5

1.5.0.0

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  Sources   Download

Apache License Version 2.0

The Requires

 

by luca bo

doctrine exception mysql connection refresh reconnect has gone away

15/12 2014

v1.4

1.4.0.0

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal

  Sources   Download

Apache License Version 2.0

The Requires

 

by luca bo

doctrine exception mysql connection refresh reconnect has gone away

16/10 2014

v1.3

1.3.0.0

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal 2.3.x

  Sources   Download

Apache License Version 2.0

The Requires

 

by luca bo

21/08 2014

v1.2

1.2.0.0

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal 2.3.x

  Sources   Download

Apache License Version 2.0

The Requires

 

by luca bo