CodeIgniter Forums
Session Library to Allow Persistent Database Connections for MySQLi - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Session Library to Allow Persistent Database Connections for MySQLi (/showthread.php?tid=71035)



Session Library to Allow Persistent Database Connections for MySQLi - Haravikk - 06-28-2018

So I'm upgrading a client's CodeIgniter based project, and have found a strange behaviour in the newer session class; it throws an exception if the database has persistent connections enabled.

This may be fine as a precaution on some drivers, but for MySQLi persistent connections should be perfectly safe, and they can have a performance benefit, so I'd like to be able to enable them again.

I'd like to propose that database drivers gain a property indicating whether they are persistence safe, so that those that are can indicate such to the session class (and others) to adapt their behaviour accordingly. Either that, or drivers where persistence is potentially unsafe simply shouldn't respect the setting at all, as there seems no point to allowing it if sessions won't work; if someone is implementing their own session handling then a means of forcing persistence could be provided instead.

Of course if there are still any persistence related issues with MySQLi don't hesitate to let me know, but I believe the MySQLi driver handles all necessary cleanup automatically.


RE: Session Library to Allow Persistent Database Connections for MySQLi - InsiteFX - 06-28-2018

Unlike the mysql extension, mysqli does not provide a separate function for opening persistent connections. To open a persistent connection you must prepend p: to the hostname when connecting.