PHP mysqli reconnect problem PHP mysqli reconnect problem php php

PHP mysqli reconnect problem


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() ?