Questions about MYSQL connections and connection time

Source: Internet
Author: User
Questions about MYSQL connections and connection time 1. access page. PHP, connect to the database, sleepfor 5 seconds, no other operations 2. the method used is not persistent connection 3. the connection timeout is set to 10 seconds. if the connection is not closed actively, should the connection be closed 10 seconds later? But it is automatically disabled in 5 seconds. Why? 1. When do you connect to the database? My Connected database is written in the configuration file. Basically, the connection count and connection time of MYSQL are displayed on the previous page.

1. access page A. PHP, connect to the database, SLEEP5 seconds, no other operations
2. the method used is not persistent connection.
3. set connection timeout to 10 seconds.


Should the connection be closed after 10 seconds if the connection is not closed actively? But it is automatically disabled in 5 seconds.
Why?

1. When do you connect to the database?
My Connected database is written in the configuration file. basically, databases are used on the previous page and are introduced in the header. However, database operations are not required to access this page.
That is to say, as long as someone accesses the file, it will connect to the database (even if sometimes no database operation is required). Is this a bad way?
The maximum number of connections in MYSQL is 5000. if there are more than 5000 users, what will happen?

2. what are the reasons for slow access to a static page? Is it related to the number of request servers? What about JS and images?

Thank you.

------ Solution --------------------
1. the connection timeout value is set to 10 seconds, which means that the database will no longer be connected when the database is not connected for 10 seconds.
2. connect to the database as needed
3. the maximum number of connections to MYSQL is 5000, indicating that an error occurs when more than 5000 clients send connection requests at the same time.
However, the number of concurrent connections allowed by the web server is limited. this will not happen. Medium-sized websites can have 10 certificates.
4. the reason for slow access to a static page: the number of files in a single directory is too large (> 1000)
------ Solution --------------------
Because the execution of a. php stops after five seconds, all resources including mysql connections will be released.

Database connections are only accessible to more than 5000 people at the same time.
------ Solution --------------------
The link will be closed after the SQL operation is complete. if the SQL operation takes more than 10 seconds, the mysql link will be closed automatically!

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.