Skip to content

Renews Doctrine DBAL connections that have been closed or timed out.

License

Notifications You must be signed in to change notification settings

jdomenechb/renew-doctrine-connection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Renew Doctrine Connection

This library eases the process of renewing an existing Doctrine connection in your application that has been closed due to a timeout from the server. This might happen when the connection expires or the server has become unavailable.

When the connection is lost, the application usually throws an error like (in MySQL):

SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

It is recommended to install this library only in daemons, consumers, PHP-only servers or very long processes, that is, any PHP project that relies solely in a lengthy PHP process to run. That does not include normal PHP applications running in web servers like Nginx or Apache, unless they have expensive algorythtms that rely on the database. Otherwise, you might be suffering some undesired overhead in your application.

Installation

Add this library to your project using Composer:

composer require jdomenechb/renew-doctrine-connection

Configuration

Modify your Doctrine configuration to use the TimedRenewConnection contained in this library as the wrapper class of Doctrine. In Symfony, for example, configuration will look like:

doctrine:
    dbal:
        # ...
        wrapper_class: 'Jdomenechb\Doctrine\DBAL\TimedRenewConnection'
        options:
            secondsToRenew: 60

You can freely customize the parameter secondsToRenew. The database connection will be renewed only after the seconds of inactivity you specify in this parameter. If it is set to 0 or not set at all, the connection will be renewed before every operation performed to the database.

For example, a good value to assign to this parameter, in MySQL, is the value of the MySQL system variable wait_timeout.

About

Renews Doctrine DBAL connections that have been closed or timed out.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages