The title of the PHP database access question is long. Several problems
First, the browser sends a request to the server. Will the server create a new thread to process the corresponding request and then return it to the browser?
Second,
If the following code is accessed:
Then, the server creates a new thread to execute this code and perform database connection and query.
So if there are N users who access the database within one minute, will they create N threads and link the database N times in this minute?
In the window, the mysql_connect function should call the. dll dynamic link library. in this case, every user needs to re-link the database once for access. is this highly efficient? Or these threads share the database link once...
I am a little white, do not spray ,,
Reply to discussion (solution)
No one answered... Amount... Amount... Amount
Is a new process...
When you access the webpage, mysql creates a connection.
1. each http session occupies an independent inbound (line) to ensure the independence of the session.
2. pay attention to the differences between loading and connection. the dynamic link library is loaded only once, and each program that uses it generates a connection for it.
3. if you want to share a connection between several inbound and outbound threads, it is not impossible. However, the scheduling between different (line) processes is very complicated. How are you going to identify the data stream to ensure it won't happen?
If 10 thousand people access the server in a short period of time, we need to create 10 thousand route entries? In addition, the life cycle of each inbound (offline) process is only accessed by users. Does the server return this short time?
Does each process have a connection to the database independently?
For example, $ con = mysql_connect ("localhost", "peter", "abc123"); does it take a long time to create a local database link?
The traditional web server is indeed a request thread, and is released after processing.
The HTTP protocol is designed to meet the lightweight and high concurrency requirements of the web.
Nginx does not seem to be a thread-opening solution with higher performance. if you are interested, please try again.
The database connection is also thread-Independent.
However, the "pool" is used in many places, such as the memory pool and thread pool.
This means adding a layer of service between the server and the database. it applies for N connections with the database in advance, saves the handle and keeps it. when there is a server in front that wants to access the database, directly use the connected handle and put it back without releasing it.