Brian Putt
Brian Putt

Reputation: 1348

Yii mysql server gone away

Setting up a queue to sit idle to process data as it comes in, from time to time I get the awesome error about the mysql server has gone away. Does anyone have any suggestions on how to gracefully fix this within Yii, when the error is given, I could re-initiate the database connection and continue.

Don't care too much for mysql settings to increase the wait_time as it can help minimize the issue but not solve it.

Edit This may seem funny/sad depending on how you look at it....I added @ symbols to the queries I was running and they were getting caught by a try-catch...I reset the database connection if the error code is within range[2006], otherwise the application returns an error......hopefully this seems like a legitimate answer...

Upvotes: 1

Views: 2093

Answers (2)

Maharjan
Maharjan

Reputation: 176

i solved by adding

max_allowed_packet = 128M
wait_timeout=3600
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

in my.cnf of mysql

Upvotes: 2

onalbi
onalbi

Reputation: 2759

I search a lot about this problem, this happens in Yii when you use especially Yii Commands. I don't know why Yii create a new connection per each AR if autoConnect is not set to false, that means to reuse a open connections.

    'db' => array(
         // Reuse a connections and not exceed the number of connections to got error 2006
        'autoConnect' => false,
         // If you are using a transactions and persistent connections
        'attributes' => array(
            PDO::ATTR_PERSISTENT => TRUE,
            PDO::ATTR_AUTOCOMMIT => FALSE
        )
    ),

Upvotes: 3

Related Questions