In short, is there some sort of mysqli_pconnect
for high-usage PHP & MySQL servers, or do I need to stick with mysql unimproved? And if so, why did they remove it?
views:
36answers:
2Support for this was introduced in PHP 5.3. For versions before this, PDO and – god forbid – the mysql extension are the only options.
To quote the manual:
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.
I don't bother with persistent connections in MySQL. Persistent connections are for databases like Oracle, in which making a new connection is much slower.
In MySQL, making a connection is relatively fast (especially if you turn off reverse DNS lookups). There should be no need for persistent connections with MySQL. If your app is performance-critical, there are tons of things you can do with greater bang for your buck than worrying about persistent connections.
Besides, persistent connections come with unintended side effects. If you use MySQL variables, temporary tables, change the character set of a connection, or forget to finish transactions, you could cause problems. For example, you could expose one user's private data to another user's PHP session because you leave a temporary table alive.