开发者

mysqli persistent connection

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 开发者_JS百科if so, why did they remove it?


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.


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.


Actually there is persistent support for mysqli library. Just prepend "p:" to the hostname and you're done.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜