{"id":22020471,"url":"https://github.com/facile-it/doctrine-mysql-come-back","last_synced_at":"2025-05-14T21:05:46.320Z","repository":{"id":19888018,"uuid":"23152524","full_name":"facile-it/doctrine-mysql-come-back","owner":"facile-it","description":"Doctrine DBAL able to try reconnect on MySQL has gone away exceptions","archived":false,"fork":false,"pushed_at":"2025-04-22T07:17:45.000Z","size":437,"stargazers_count":203,"open_issues_count":5,"forks_count":43,"subscribers_count":37,"default_branch":"3.x","last_synced_at":"2025-04-22T08:28:15.358Z","etag":null,"topics":["doctrine-dbal","hacktoberfest","mysql","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/facile-it.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-08-20T14:53:51.000Z","updated_at":"2025-03-17T08:56:13.000Z","dependencies_parsed_at":"2024-06-18T12:41:30.355Z","dependency_job_id":"068b97ee-dc39-43bb-9558-d644c2f1efae","html_url":"https://github.com/facile-it/doctrine-mysql-come-back","commit_stats":{"total_commits":203,"total_committers":23,"mean_commits":8.826086956521738,"dds":"0.35467980295566504","last_synced_commit":"f0114b65b0186e6a8f8811595b58309904401d26"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facile-it%2Fdoctrine-mysql-come-back","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facile-it%2Fdoctrine-mysql-come-back/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facile-it%2Fdoctrine-mysql-come-back/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facile-it%2Fdoctrine-mysql-come-back/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/facile-it","download_url":"https://codeload.github.com/facile-it/doctrine-mysql-come-back/tar.gz/refs/heads/3.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254227611,"owners_count":22035669,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["doctrine-dbal","hacktoberfest","mysql","php"],"created_at":"2024-11-30T06:06:34.752Z","updated_at":"2025-05-14T21:05:46.237Z","avatar_url":"https://github.com/facile-it.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](https://poser.pugx.org/facile-it/doctrine-mysql-come-back/v/stable.svg)](https://packagist.org/packages/facile-it/doctrine-mysql-come-back) \n[![Latest Unstable Version](https://poser.pugx.org/facile-it/doctrine-mysql-come-back/v/unstable.svg)](https://packagist.org/packages/facile-it/doctrine-mysql-come-back) \n[![Total Downloads](https://poser.pugx.org/facile-it/doctrine-mysql-come-back/downloads.svg)](https://packagist.org/packages/facile-it/doctrine-mysql-come-back) \n\n[![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)\n[![Test coverage](https://codecov.io/gh/facile-it/doctrine-mysql-come-back/branch/master/graph/badge.svg?token=vFz9cWGQ3r)](https://codecov.io/gh/facile-it/doctrine-mysql-come-back)\n[![License](https://poser.pugx.org/facile-it/doctrine-mysql-come-back/license.svg)](https://packagist.org/packages/facile-it/doctrine-mysql-come-back)\n\n# DoctrineMySQLComeBack\n\nThis library tries to solve the infamous \"MySQL has gone away\" issue, and similar ones. \n\nIt 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).\n\n# Installation\n\nIf you're using DBAL 4.0+\n```console\n$ composer require facile-it/doctrine-mysql-come-back ^3.0\n```\n\nIf you're using DBAL 3.6+\n```console\n$ composer require facile-it/doctrine-mysql-come-back ^2.0\n```\n\nIf you're using DBAL `^2.3`\n```console\n$ composer require facile-it/doctrine-mysql-come-back ^1.0\n```\n\n# Configuration\n\nIn order to use DoctrineMySQLComeBack you have to set the `wrapperClass` connection parameter.\nYou can choose how many times Doctrine should be able to reconnect, setting `x_reconnect_attempts` driver option. Its value must be an int.\n\nIf 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.\n\nAn example of configuration at connection instantiation time:\n\n```php\nuse Doctrine\\DBAL\\Configuration;\nuse Doctrine\\DBAL\\DriverManager;\n\n$config = new Configuration();\n\n//..\n\n$connectionParams = [\n    'dbname' =\u003e 'mydb',\n    'user' =\u003e 'user',\n    'password' =\u003e 'secret',\n    'host' =\u003e 'localhost',\n    // [doctrine-mysql-come-back] settings\n    'wrapperClass' =\u003e 'Facile\\DoctrineMySQLComeBack\\Doctrine\\DBAL\\Connection',\n    'driverOptions' =\u003e [\n        'x_reconnect_attempts' =\u003e 3\n    ],\n];\n\n$conn = DriverManager::getConnection($connectionParams, $config);\n\n//..\n```\n\nAn example of yaml configuration on Symfony projects:\n\n```yaml\ndoctrine:\n    dbal:\n        connections:\n            default:\n                # DATABASE_URL would be of \"mysql://db_user:db_password@127.0.0.1:3306/db_name\" \n                url: '%env(resolve:DATABASE_URL)%'\n                wrapper_class: 'Facile\\DoctrineMySQLComeBack\\Doctrine\\DBAL\\Connection'\n                options:\n                    x_reconnect_attempts: 3\n``` \n\nAn example of configuration on Laminas Framework 2projects:\n\n```php\nreturn [\n    'doctrine' =\u003e [\n        'connection' =\u003e [\n            'orm_default' =\u003e [\n                'wrapperClass' =\u003e \\Facile\\DoctrineMySQLComeBack\\Doctrine\\DBAL\\Connection::class,\n                'params' =\u003e [\n                    'host' =\u003e 'localhost',\n                    'port' =\u003e '3307',\n                    'user' =\u003e '##user##',\n                    'password' =\u003e '##password##',\n                    'dbname' =\u003e '##database##',\n                    'charset' =\u003e 'UTF8',\n                    'driverOptions' =\u003e [\n                        'x_reconnect_attempts' =\u003e 9,\n                    ]\n                ],\n            ],\n        ],\n    ],\n];\n```\n\nYou can use wrapper class `Facile\\DoctrineMySQLComeBack\\Doctrine\\DBAL\\Connections\\PrimaryReadReplicaConnection` if you are using a primary/replica Doctrine configuration:\n```php\nuse Doctrine\\DBAL\\Configuration;\nuse Doctrine\\DBAL\\DriverManager;\n\n$config = new Configuration();\n\n//..\n\n$connectionParams = [\n    'wrapperClass' =\u003e 'Facile\\DoctrineMySQLComeBack\\Doctrine\\DBAL\\PrimaryReadReplicaConnection',\n    'primary' =\u003e [\n        // ...\n        'driverOptions' =\u003e [\n            'x_reconnect_attempts' =\u003e 3\n        ],\n    ],   \n];\n\n$conn = DriverManager::getConnection($connectionParams, $config);\n\n//..\n```\n\n# Usage\n\nSince 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.\n\nFrom `v1.6` of this library automagically reconnection is enabled also during `$em-\u003egetConnection()-\u003ebeginTransaction()` calls,\nand this works also during simple `$em-\u003eflush()`, if out of a previous transaction.\n\n# Thanks\nThanks to Dieter Peeters and his proposal on [DBAL-275](https://github.com/doctrine/dbal/issues/1454).\nCheck it out if you are using doctrine/dbal \u003c2.3.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacile-it%2Fdoctrine-mysql-come-back","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffacile-it%2Fdoctrine-mysql-come-back","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacile-it%2Fdoctrine-mysql-come-back/lists"}