PHPcliwhile (true) sleep (60) mysql

Source: Internet
Author: User
Tags connection pooling pconnect php cli
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

  1. Create a mysql connection
  2. Execute batch write
  3. Php manually ends the mysql connection (in fact, the mysql connection is not completed, but php is released)
  4. Php stops running and releases memory
  5. Mysql connection processes the sleep status.
  6. 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

  1. Create a mysql connection
  2. Execute batch write
  3. Php manually ends the mysql connection (in fact, the mysql connection is not completed, but php is released)
  4. Php stops running and releases memory
  5. Mysql connection processes the sleep status.
  6. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.