It looks like my CI database config is in fact configured to use persistent connections, so I'll be changing that because yes I agree that persistent connections cause more annoyance than performance boost. for reference this is what the CI database config looks like:
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'dbuserxxx',
'password' => 'dbpassxxx',
'database' => 'my_db_name',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE, // change this to false
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'autoinit' => TRUE,
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
How do the mechanics of these connections work? The mysql command-line client seems pretty simple to me. You connect and authenticate and it listens to you until at some point you sit idle long enough and it disconnects you and closes the socket.
But how does it work when you have Apache running numerous threads, each of which might be connecting to the db? Are persistent connections maintained between subsequent page requests? How do the Apache/PHP processes interact with some pool of connections (if any such pool exists)?
I've always wondered exactly what it means to user a persistent database connection but haven't really seen a thorough explanation. This gets close, but I still feel like it could be described more clearly.