PHP CLI while (true) sleep (MySQL)

Source: Internet
Author: User
Tags pconnect php cli
Suppose you have a php CLI file that runs every 2 minutes to perform MySQL data write operations.

If you use Corntab or MQ, every execution is

    1. Establish a MySQL connection
    2. Performing Bulk writes
    3. PHP manually end MySQL connection (actually MySQL connection is not finished, just PHP release)
    4. PHP ends Running free memory
    5. At this point, MySQL connection handles the sleep state
    6. After 2 minutes, execute 1 ~ 5 again

The script every 2 minutes, 24 hours down, MySQL will produce a lot of sleep connection, even if the optimization of MySQL wait_timeout thread_cache_size These parameters are not used?

If it is while (true), PHP uses pconnect only to establish a MySQL connection, as long as the PHP process is running, will never release MySQL connection right?

Does this save MySQL connections, thereby reducing the pressure on MySQL servers?

Reply content:

Suppose you have a php CLI file that runs every 2 minutes to perform MySQL data write operations.

If you use Corntab or MQ, every execution is

    1. Establish a MySQL connection
    2. Performing Bulk writes
    3. PHP manually end MySQL connection (actually MySQL connection is not finished, just PHP release)
    4. PHP ends Running free memory
    5. At this point, MySQL connection handles the sleep state
    6. After 2 minutes, execute 1 ~ 5 again

The script every 2 minutes, 24 hours down, MySQL will produce a lot of sleep connection, even if the optimization of MySQL wait_timeout thread_cache_size These parameters are not used?

If it is while (true), PHP uses pconnect only to establish a MySQL connection, as long as the PHP process is running, will never release MySQL connection right?

Does this save MySQL connections, thereby reducing the pressure on MySQL servers?

A CLI 2 minutes to run and no concurrency, just to see the database read the operation if there is a read-write separation on the solution. Optimizing PHP Connection Pooling This is too difficult.

  • 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.