Swoole MySQL Proxy, a MySQL database connection pool developed by Swoole based on the MySQL protocol.
Principle
Store the database connection as an object in memory. When the user needs to access the database, the connection will be established for the first time. Instead of establishing a new connection, an established idle connection object is taken out of the connection pool. After use, the user does not close the connection, but puts the connection back into the connection pool for the next request. The establishment and disconnection of connections are managed by the connection pool itself.
At the same time, you can also control the initial number of connections in the connection pool, the upper and lower limits of connections, the maximum number of uses of each connection, the maximum idle time, etc. by setting the parameters of the connection pool. It can also monitor the number, usage, etc. of database connections through its own management mechanism. If the maximum number of connections is exceeded, the coroutine will be suspended, and the coroutine will be resumed until a connection is closed to continue the operation.
Features
-Supports read-write separation
-Supports database connection pool, which can effectively solve the database connection bottleneck caused by PHP
-Support SQL92 standard
-Adopt coroutine scheduling
-Support multiple database connections, multiple databases, multiple users, flexible combination
-Comply with MySQL native Protocol, cross-language, cross-platform universal middleware agent
-Supports MySQL transactions
-Supports HandshakeV10 protocol version
-Perfectly compatible with MySQL4.1 - 8.0
-Compatible with major frameworks, seamlessly improve performance
Original design intention
PHP does not have a connection pool, so the database will be full of connections when concurrency is high. , Mycat and other database middleware will cause some SQL to be unusable, for example, batch addition is not supported, and it is too bloated. So I wrote this lightweight middleware that only supports connection pooling and read-write separation. Using Swoole coroutine scheduling and HandshakeV10 protocol forwarding makes the program more stable. There is no need to parse all SQL package bodies like Mycat, which increases complexity.
Recommended tutorial: "mysql tutorial"http://www.php.cn/course/list/51.html
#
The above is the detailed content of MySQL database connection pool SMProxy. For more information, please follow other related articles on the PHP Chinese website!