User Contributed Notes 3 notes

As jay at grooveshark dot com very helpfully pointed out, the mysqlnd driver which is becoming pretty standard does not obey reconnect commands. If you have a DB wrapper class (which hopefully you do) you can implement your own version of ping() such as:

$db = new db(DB_HOST, DB_USER, DB_PASS, DB_NAME);// Some code that potentially takes a really long time to execute goes here// Ping for safety to try to gracefully reconnect$db->ping();// Now we should be able to run queries again$db->query('SELECT LAST_INSERT_ID()');

?>

If you wanted you could even put "$this->ping();" at the top of db::query() to avoid any explicit reconnection calls but I wouldn't recommend it due to the (slight) overhead of running the cheap "SELECT LAST_INSERT_ID()" query every time prior to running your real intended query. There are probably even cheaper queries to run in favor of "SELECT LAST_INSERT_ID()" but it was the first that came to mind and is cheap enough for most purposes since you shouldn't be calling ping() a whole bunch anyway.

The behaviour about the option mysqli.reconnect is default set to Off at Debian PHP Packages. So i would recommend to update the first line description about the recommendation at the option mysqli.reconnect. (practice note ;))