Assume that there is a phpcli file that runs every two minutes to write mysql Data. If you use corntab or mq, you need to establish a mysql connection for each execution and write data to php in batches to manually end the mysql connection (in fact, the mysql connection is not completed,... assume that there is a php cli file that runs every two minutes to write mysql Data.
If you use corntab or mq, each execution requires
- Create a mysql connection
- Execute batch write
- Php manually ends the mysql connection (in fact, the mysql connection is not completed, but php is released)
- Php stops running and releases memory
- Mysql connection processes the sleep status.
- Run 1 ~ 5
Mysql generates a large number of sleep connections Every 2 minutes and 24 hours. Even if the wait_timeout thread_cache_size parameter of mysql is optimized, isn't it?
If it is while (true), php uses pconnect to establish only one mysql connection. As long as the php process is running, Will mysql connection never be released?
In this way, can the number of mysql connections be reduced to reduce the pressure on the mysql server?
Reply content:
Assume that there is a php cli file that runs every two minutes to write mysql Data.
If you use corntab or mq, each execution requires
- Create a mysql connection
- Execute batch write
- Php manually ends the mysql connection (in fact, the mysql connection is not completed, but php is released)
- Php stops running and releases memory
- Mysql connection processes the sleep status.
- Run 1 ~ 5
Mysql generates a large number of sleep connections Every 2 minutes and 24 hours. Even if the wait_timeout thread_cache_size parameter of mysql is optimized, isn't it?
If it is while (true), php uses pconnect to establish only one mysql connection. As long as the php process is running, Will mysql connection never be released?
In this way, can the number of mysql connections be reduced to reduce the pressure on the mysql server?
A cli runs once every 2 minutes without concurrency. You only need to check whether the database read operations can be implemented if there is any read/write splitting. It is too difficult to optimize the connection pooling of php.