Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Shutdown event issue
  • Hi,

    Since some days, i see often mysql error like that : 

    21/11/2017 14:51stderr2017-11-21T13:51:10.077302Z 58182 [Note] Aborted connection 58182 to db: 'xsc_prod' user: 'xsc_prod' host: 'XXXX' (Got timeout reading communication packets)
    21/11/2017 14:52stderr2017-11-21T13:52:38.305168Z 58591 [Note] Aborted connection 58591 to db: 'xsc_prod' user: 'xsc_prod' host: 'XXXX' (Got timeout reading communication packets)

    And i need to reboot the mysql server.

    After several searches, it would be because the application does not close the mysql connections.

    So I decided to put a log in the "connect" and "disconnect" method of the "Database_PDO_Connection" class.

    After tests, I see the log of the "connect()" method, but no trace of the disconnect() method.

    So I tried to put this line in bootstrap.php:

    \Event::register('shutdown', 'Database_Connection::disconnect');


    But still no sign of disconnect().

    Do you have any advice?
  • Finally, my fix : 

    $mysqlDisconnectEvent = function() {
    if (isset(\Database_Connection::$instances['default']))
    {
    \Database_Connection::$instances['default']->disconnect();
    }
    \Profiler::console('SHUTDOWN EVENT');
    };

    \Event::register('shutdown', $mysqlDisconnectEvent);


    It's good ?
  • Should work. 

    But I doubt if it makes any difference, PHP closes all connections automatically on shutdown, The PDO object has a destructor that closes the connection if not already closed.

    There are a lot of possible causes for this warning. I find that https://www.percona.com/blog/2016/05/16/mysql-got-an-error-reading-communication-packet-errors/ gives a pretty accurate list.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion