php 连接池 mysql

2022-01-24 00:00:00 connection connection-pooling php mysql

我打算使用 MYSQL.是否有可用的连接池扩展?或者连接的正常做法是什么?是不是到处都用这个...

I am planning to use MYSQL. Is there a connection pooling extension available? Or what is the normal practice for connection? Is this the one used in every where...

mysqli_connect("localhost", "xxx", "xxx", "test");

人们是否只使用普通的 mysql_connectpconnect..?pconnect 有多好,我应该为 PConnect 做哪些设置?

Do people use just normal mysql_connect or pconnect..? How better is pconnect and what setting should I do for PConnect?

推荐答案

你用过 mysql_pconnect() 吗?mysql_pconnect() 的行为与 mysql_connect() 非常相似,但有两个主要区别.

have you ever used mysql_pconnect() ? mysql_pconnect() acts very much like mysql_connect() with two major differences.

首先,在连接时,该函数将首先尝试查找已使用相同主机、用户名和密码打开的(永久)链接.如果找到,将返回它的标识符,而不是打开新连接.

First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

其次,脚本执行结束时不会关闭与SQL服务器的连接.相反,该链接将保持打开状态以供将来使用(mysql_close() 不会关闭由 mysql_pconnect() 建立的链接).

Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).

因此这种类型的链接被称为持久"

This type of link is therefore called 'persistent'

检查它这里

相关文章