PHP mysqli reconnect problem

荒凉一梦 提交于 2019-11-30 18:29:22

The doc for mysqli_ping() says that if you set the global option mysqli.reconnect to 1 (in your php.ini) then mysqli_ping() will reconnect when it detects the connection has gone away.

Update: Since I answered this question in 2009, PHP has mostly moved on to use the mysqlnd driver by default instead of libmysql. As mentioned in the comment below, mysqlnd does not support the mysqli_ping() function, and the PHP developers did this intentionally, according to their "Won't Fix" answer in https://bugs.php.net/bug.php?id=52561

So there appears to be no solution for automatic reconnect in PHP anymore.

u can try something a bit different .. instead of ping .. try to send a really simple low intensity query like "select now()" and see if you get any better results.

Can't you use persistent connections? Also, is that really necessary to fork() ?

function IsConnected() {
    if (empty($this->_connectionID) === FALSE && mysqli_ping($this->_connectionID) === TRUE) {
        return true; // still have connect
    }
    $this->_connectionID = false;
    return false; // lose connection
}

Use http://www.php.net/manual/en/mysqli.real-connect.php ... reinstall php and check your php.ini settings

I think you need to set mysqli.reconnect in my.cng, which is the mysql config, rather than php.ini, I couldn't manage to change reconnect via ini_set, but my sys admin did it in my.cnf.

So, tad confused that others have done it within php.ini....

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!