PHPackages                             facile-it/doctrine-mysql-come-back - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. facile-it/doctrine-mysql-come-back

ActiveLibrary[Database &amp; ORM](/categories/database)

facile-it/doctrine-mysql-come-back
==================================

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

3.0.3(8mo ago)2113.1M↓10.9%47[4 issues](https://github.com/facile-it/doctrine-mysql-come-back/issues)[2 PRs](https://github.com/facile-it/doctrine-mysql-come-back/pulls)4Apache-2.0PHPPHP ^8.1CI passing

Since Aug 21Pushed 1mo ago35 watchersCompare

[ Source](https://github.com/facile-it/doctrine-mysql-come-back)[ Packagist](https://packagist.org/packages/facile-it/doctrine-mysql-come-back)[ RSS](/packages/facile-it-doctrine-mysql-come-back/feed)WikiDiscussions 3.x Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (38)Used By (4)

[![Latest Stable Version](https://camo.githubusercontent.com/23fd5b7c10935046a2a76de717cfe5456bfda0db7f9ed634eb14dfbf4ef5f5e3/68747470733a2f2f706f7365722e707567782e6f72672f666163696c652d69742f646f637472696e652d6d7973716c2d636f6d652d6261636b2f762f737461626c652e737667)](https://packagist.org/packages/facile-it/doctrine-mysql-come-back)[![Latest Unstable Version](https://camo.githubusercontent.com/bde027a7b715f5e83164467e5b8ad83a8cedda1728b287ca5406754a3cf93950/68747470733a2f2f706f7365722e707567782e6f72672f666163696c652d69742f646f637472696e652d6d7973716c2d636f6d652d6261636b2f762f756e737461626c652e737667)](https://packagist.org/packages/facile-it/doctrine-mysql-come-back)[![Total Downloads](https://camo.githubusercontent.com/e8845799e3db2152ed7516638e16752b9d705f27268b582ec80093fb82f536fa/68747470733a2f2f706f7365722e707567782e6f72672f666163696c652d69742f646f637472696e652d6d7973716c2d636f6d652d6261636b2f646f776e6c6f6164732e737667)](https://packagist.org/packages/facile-it/doctrine-mysql-come-back)

[![Build status](https://github.com/facile-it/doctrine-mysql-come-back/workflows/Continuous%20Integration/badge.svg)](https://github.com/facile-it/doctrine-mysql-come-back/actions?query=workflow%3A%22Continuous+Integration%22+branch%3Amaster)[![Test coverage](https://camo.githubusercontent.com/15197cae96936f50585dd80cfc2e6bf648c697b35f2935ac5442e5dd93920819/68747470733a2f2f636f6465636f762e696f2f67682f666163696c652d69742f646f637472696e652d6d7973716c2d636f6d652d6261636b2f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d76467a39635747513372)](https://codecov.io/gh/facile-it/doctrine-mysql-come-back)[![License](https://camo.githubusercontent.com/4d3bb1e58737f8136dcb0a956e42d36cfcebc48017f4ca4408b141ec93be3f4f/68747470733a2f2f706f7365722e707567782e6f72672f666163696c652d69742f646f637472696e652d6d7973716c2d636f6d652d6261636b2f6c6963656e73652e737667)](https://packagist.org/packages/facile-it/doctrine-mysql-come-back)

DoctrineMySQLComeBack
=====================

[](#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
============

[](#installation)

If you're using DBAL 4.0+

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

If you're using DBAL 3.6+

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

If you're using DBAL `^2.3`

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

Configuration
=============

[](#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](https://github.com/facile-it/doctrine-mysql-come-back/blob/1.10.1/README.md#configuration) for that.

An example of configuration at connection instantiation time:

```
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:

```
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:

```
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:

```
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
=====

[](#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)

Thanks to Dieter Peeters and his proposal on [DBAL-275](https://github.com/doctrine/dbal/issues/1454). Check it out if you are using doctrine/dbal &lt;2.3.

###  Health Score

68

—

FairBetter than 100% of packages

Maintenance76

Regular maintenance activity

Popularity61

Solid adoption and visibility

Community35

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 70% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~124 days

Recently: every ~82 days

Total

35

Last Release

62d ago

Major Versions

1.10.1 → 2.0.0-BETA12022-06-23

2.0.0 → 3.0.02024-03-10

2.0.2 → 3.0.32025-09-02

2.x-dev → 3.x-dev2026-03-17

PHP version history (7 changes)v1.6.1PHP &gt;=5.4

v1.6.3PHP ^5.4 || ^7.0

v1.6.4PHP ^5.6 || ^7.0

v1.9.0PHP ^7.3

1.10.0PHP ^7.3 || ^8.0

2.0.0-BETA2PHP ^7.4 || ^8.0

3.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d554b89e86bd5424ad034cf03e517ef708c2e81cd4fe74c9da00ffd1d10cc564?d=identicon)[peelandsee](/maintainers/peelandsee)

---

Top Contributors

[![Jean85](https://avatars.githubusercontent.com/u/6729988?v=4)](https://github.com/Jean85 "Jean85 (245 commits)")[![peelandsee](https://avatars.githubusercontent.com/u/1212677?v=4)](https://github.com/peelandsee "peelandsee (35 commits)")[![thomasvargiu](https://avatars.githubusercontent.com/u/732012?v=4)](https://github.com/thomasvargiu "thomasvargiu (27 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (13 commits)")[![oleg-andreyev](https://avatars.githubusercontent.com/u/1244112?v=4)](https://github.com/oleg-andreyev "oleg-andreyev (7 commits)")[![Capitrium](https://avatars.githubusercontent.com/u/5111534?v=4)](https://github.com/Capitrium "Capitrium (6 commits)")[![lkck24](https://avatars.githubusercontent.com/u/17538220?v=4)](https://github.com/lkck24 "lkck24 (2 commits)")[![alexmanno](https://avatars.githubusercontent.com/u/10499850?v=4)](https://github.com/alexmanno "alexmanno (2 commits)")[![Algatux](https://avatars.githubusercontent.com/u/888864?v=4)](https://github.com/Algatux "Algatux (2 commits)")[![maxcanna](https://avatars.githubusercontent.com/u/1881831?v=4)](https://github.com/maxcanna "maxcanna (2 commits)")[![peter17](https://avatars.githubusercontent.com/u/752832?v=4)](https://github.com/peter17 "peter17 (2 commits)")[![LewisW](https://avatars.githubusercontent.com/u/17803?v=4)](https://github.com/LewisW "LewisW (1 commits)")[![lattwood](https://avatars.githubusercontent.com/u/6198952?v=4)](https://github.com/lattwood "lattwood (1 commits)")[![gordinskiy](https://avatars.githubusercontent.com/u/72280830?v=4)](https://github.com/gordinskiy "gordinskiy (1 commits)")[![roslov](https://avatars.githubusercontent.com/u/6573063?v=4)](https://github.com/roslov "roslov (1 commits)")[![starred-gijs](https://avatars.githubusercontent.com/u/42832118?v=4)](https://github.com/starred-gijs "starred-gijs (1 commits)")[![ackermannd](https://avatars.githubusercontent.com/u/2496882?v=4)](https://github.com/ackermannd "ackermannd (1 commits)")[![taueres](https://avatars.githubusercontent.com/u/3669079?v=4)](https://github.com/taueres "taueres (1 commits)")

---

Tags

doctrine-dbalhacktoberfestmysqlphpmysqldoctrineexceptionConnectionrefreshreconnecthas gone away

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/facile-it-doctrine-mysql-come-back/health.svg)

```
[![Health](https://phpackages.com/badges/facile-it-doctrine-mysql-come-back/health.svg)](https://phpackages.com/packages/facile-it-doctrine-mysql-come-back)
```

###  Alternatives

[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58723.9M36](/packages/scienta-doctrine-json-functions)[fresh/doctrine-enum-bundle

Provides support of ENUM type for Doctrine2 in Symfony applications.

4636.8M12](/packages/fresh-doctrine-enum-bundle)[oro/doctrine-extensions

Doctrine Extensions for MySQL and PostgreSQL.

34411.8M19](/packages/oro-doctrine-extensions)[nettrine/dbal

Doctrine DBAL for Nette Framework

322.6M19](/packages/nettrine-dbal)[marktopper/doctrine-dbal-timestamp-type

Add the timestamp type for Doctrine/DBAL

49808.2k1](/packages/marktopper-doctrine-dbal-timestamp-type)[pharako/mysql-dbal

MySQL extensions for Doctrine DBAL

2416.2k](/packages/pharako-mysql-dbal)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
