PHPackages                             adgoal/dbal-fault-tolerance - 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. adgoal/dbal-fault-tolerance

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

adgoal/dbal-fault-tolerance
===========================

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

v1.9.2(6y ago)01.4kApache-2.0PHPPHP ^7.1

Since Aug 21Pushed 6y agoCompare

[ Source](https://github.com/Adgoal/dbal-fault-tolerance)[ Packagist](https://packagist.org/packages/adgoal/dbal-fault-tolerance)[ RSS](/packages/adgoal-dbal-fault-tolerance/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (11)Versions (20)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/dc665bc845c7057593d2edc7ffc8d15a05188b08ff99661ea2540d499a9b5b19/68747470733a2f2f706f7365722e707567782e6f72672f6164676f616c2f6462616c2d6661756c742d746f6c6572616e63652f762f737461626c652e737667)](https://packagist.org/packages/adgoal/dbal-fault-tolerance)[![Latest Unstable Version](https://camo.githubusercontent.com/ef0d1da06d82cbd951667faa798bce8e7e4e8ee43ecb1adf9fcf3a2b816ff93f/68747470733a2f2f706f7365722e707567782e6f72672f6164676f616c2f6462616c2d6661756c742d746f6c6572616e63652f762f756e737461626c652e737667)](https://packagist.org/packages/adgoal/dbal-fault-tolerance)[![Total Downloads](https://camo.githubusercontent.com/7aa610381e2dc0e13d24d497f2689b844081fd3550017e2b7a8990373d412157/68747470733a2f2f706f7365722e707567782e6f72672f6164676f616c2f6462616c2d6661756c742d746f6c6572616e63652f646f776e6c6f6164732e737667)](https://packagist.org/packages/adgoal/dbal-fault-tolerance)

[![Build status](https://camo.githubusercontent.com/d9bbe524303315a9aa7fb09be8050c142bda7539bba1bf932985e7b1ecdd4a0a/68747470733a2f2f7472617669732d63692e6f72672f6164676f616c2f6462616c2d6661756c742d746f6c6572616e63652e737667)](https://travis-ci.org/adgoal/dbal-fault-tolerance)[![Scrutinizer score](https://camo.githubusercontent.com/64d276916118a93cd26ec90e87f1db17d31a837269aa8948161a8b9c037de9ae/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6164676f616c2f6462616c2d6661756c742d746f6c6572616e63652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/adgoal/dbal-fault-tolerance/?branch=master)[![Test coverage](https://camo.githubusercontent.com/6f7ab39c4cf60cc9c69e81546b342c39a96cd909f201cae92b3be640014a13e1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6164676f616c2f6462616c2d6661756c742d746f6c6572616e63652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/adgoal/dbal-fault-tolerance/?branch=master)

[![License](https://camo.githubusercontent.com/c1b6e1f4dc020a5ad24be0d7482dce8eb64dbb3eb65395cdb8add5e7e05967d8/68747470733a2f2f706f7365722e707567782e6f72672f6164676f616c2f6462616c2d6661756c742d746f6c6572616e63652f6c6963656e73652e737667)](https://packagist.org/packages/adgoal/dbal-fault-tolerance)

DBALFaultTolerance
==================

[](#dbalfaulttolerance)

Auto reconnect on Doctrine MySql has gone away exceptions on doctrine/dbal &gt;=2.3, &lt;3.0.

Installation
============

[](#installation)

```
$ composer require adgoal/dbal-fault-tolerance
```

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

[](#configuration)

In order to use DBALFaultTolerance you have to set `wrapperClass` and `driverClass` connection params. You can choose how many times Doctrine should be able to reconnect, setting `x_reconnect_attempts` driver option. Its value should be an int.

You can force ignore the transaction level using the parameters : `force_ignore_transaction_level`.

An example of configuration at connection instantiation time:

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

$config = new Configuration();

//..

$connectionParams = array(
    'dbname' => 'mydb',
    'user' => 'user',
    'password' => 'secret',
    'host' => 'localhost',
    // [dbal-fault-tolerance] settings
    'wrapperClass' => Adgoal\DBALFaultTolerance\Connection::class,
    'driverClass' => Adgoal\DBALFaultTolerance\Driver\PDOMySql\Driver::class,
    'driverOptions' => [
        'x_reconnect_attempts' => 3,
        'force_ignore_transaction_level' => true
    ]
);

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

//..
```

An example of yaml configuration on Symfony 2 projects:

```
# Doctrine example Configuration
doctrine:
    dbal:
        default_connection: %connection_name%
        connections:
            %connection_name%:
                host:     %database_host%
                port:     %database_port%
                dbname:   %database_name%
                user:     %database_user%
                password: %database_password%
                charset:  UTF8
                wrapper_class: 'Adgoal\DBALFaultTolerance\Connection'
                driver_class: 'Adgoal\DBALFaultTolerance\Driver\PDOMySql\Driver'
                options:
                    x_reconnect_attempts: 3
```

An example of configuration on Zend Framework 2/3 projects:

```
return [
    'doctrine' => [
        'connection' => [
            'orm_default' => [
                'driverClass' => \Adgoal\DBALFaultTolerance\Driver\PDOMySql\Driver::class,
                'wrapperClass' => \Adgoal\DBALFaultTolerance\Connection::class,
                'params' => [
                    'host' => 'localhost',
                    'port' => '3307',
                    'user' => '##user##',
                    'password' => '##password##',
                    'dbname' => '##database##',
                    'charset' => 'UTF8',
                    'driverOptions' => [
                        'x_reconnect_attempts' => 9,
                        'force_ignore_transaction_level' => true
                    ]
                ],
            ],
        ],
    ],
];
```

You can use wrapper class `Adgoal\DBALFaultTolerance\Connections\MasterSlaveConnection` if you are using master / slave Doctrine configuration.

Usage
=====

[](#usage)

To force a reconnection try after a long running task you can call

```
$em->getConnection()->refresh();
```

before performing any other operation different from SELECT.

Instead, in case your next query will be a SELECT, reconnection will be automagically done.

From `v1.6` 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

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~103 days

Recently: every ~6 days

Total

19

Last Release

2417d ago

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

v1.6.3PHP ^5.4 || ^7.0

v1.6.4PHP ^5.6 || ^7.0

1.9PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/f4d59ea4bdf00e8a2b7ac18da994d769a06136ca1cfdf9e17306e235901cac31?d=identicon)[wir\_wolf](/maintainers/wir_wolf)

---

Top Contributors

[![peelandsee](https://avatars.githubusercontent.com/u/1212677?v=4)](https://github.com/peelandsee "peelandsee (34 commits)")[![Jean85](https://avatars.githubusercontent.com/u/6729988?v=4)](https://github.com/Jean85 "Jean85 (21 commits)")[![thomasvargiu](https://avatars.githubusercontent.com/u/732012?v=4)](https://github.com/thomasvargiu "thomasvargiu (15 commits)")[![wirwolf](https://avatars.githubusercontent.com/u/8457572?v=4)](https://github.com/wirwolf "wirwolf (8 commits)")[![alexmanno](https://avatars.githubusercontent.com/u/10499850?v=4)](https://github.com/alexmanno "alexmanno (8 commits)")[![Capitrium](https://avatars.githubusercontent.com/u/5111534?v=4)](https://github.com/Capitrium "Capitrium (6 commits)")[![avardbacon](https://avatars.githubusercontent.com/u/2482114?v=4)](https://github.com/avardbacon "avardbacon (4 commits)")[![Algatux](https://avatars.githubusercontent.com/u/888864?v=4)](https://github.com/Algatux "Algatux (4 commits)")[![maxcanna](https://avatars.githubusercontent.com/u/1881831?v=4)](https://github.com/maxcanna "maxcanna (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)")[![accountmanager](https://avatars.githubusercontent.com/u/7573730?v=4)](https://github.com/accountmanager "accountmanager (1 commits)")[![starred-gijs](https://avatars.githubusercontent.com/u/42832118?v=4)](https://github.com/starred-gijs "starred-gijs (1 commits)")[![taueres](https://avatars.githubusercontent.com/u/3669079?v=4)](https://github.com/taueres "taueres (1 commits)")

---

Tags

mysqldoctrineexceptionConnectionrefreshreconnecthas gone away

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/adgoal-dbal-fault-tolerance/health.svg)

```
[![Health](https://phpackages.com/badges/adgoal-dbal-fault-tolerance/health.svg)](https://phpackages.com/packages/adgoal-dbal-fault-tolerance)
```

###  Alternatives

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

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

2113.1M4](/packages/facile-it-doctrine-mysql-come-back)[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[scienta/doctrine-json-functions

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

58523.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)[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)

PHPackages © 2026

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