php-cp (php-connect-pool) is a database connection pool written with PHP extension.
1. It is different from other open source database middleware products on the market
1. It does not require separate deployment of middleware A cluster is a proxy process running on an application server, which reduces a layer of external dependencies, making the architecture simpler, cleaner, and more reliable.
2. It has higher performance and reduces one network transmission. It communicates with the PHP process through efficient IPC and avoids the consumption of protocol parsing.
3. Supports redis and mysql at the same time, no need to deploy two separate middleware systems.
2. Simple schematic diagram
##3. Technical characteristics
1. Supports the configuration of the maximum and minimum number of connections. 2. Supports automatic recovery of connections with low pressure (strength and frequency are configurable). 3. Support smooth restart. 4. Support the queuing mechanism of connection exhaustion. 5. Supports both mysql and redis. 6. It is easy to use. After simple integration of the framework (modifying the new method), the existing business can use the connection pool without changing a single line of code. 7. The get_disable_list function is provided to obtain a list of unavailable downtime IPs, so that load balancing can also be done on the client (make a difference between all IPs in the configuration file and the downtime IP, and then randomly Can). btw: You can also use lvs, but lvs forwarding introduces dependencies on the system architecture. The DR mode cannot cross network segments and limits expansion. If there is a problem with the back-end db, you can only know the VIP of lvs. 8. The connection pool process will start the ping process to monitor the downtime list. If available, it will be reflected in the return value of the get_disable_list function. 9. A lot of optimizations have been made, although the request passes through the connection Pool process forwarding, but basically no qps loss.4. How to use
1. Place the pool.ini file in /etc/ and modify the configuration inside as needed. 2. Start the agent process./pool_server start
$db = new PDO(xxxxx); 修改成 $db = new pdo_connect_pool(xxxx);//dont use persistent $redis = new Redis(); 修改成 $redis = new redis_connect_pool();//dont use pconnect
Tips:
Call $db/$redis->release() as soon as possible to release the connections occupied by this process into the pool. Recommended tutorial:The above is the detailed content of Does php have a database connection pool?. For more information, please follow other related articles on the PHP Chinese website!