tags:

views:

36

answers:

2

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?

+2  A: 

Support 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.

Artefacto
A: 

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.

Bill Karwin
Read the manual page to which I've linked. There are cleanup operations after each PHP request. But yes, most of the times it using persistent connections won't be worth it.
Artefacto
Thanks, that's reassuring.
Bill Karwin