PHP has two function when it connects MySQL
Connect and Pconnect
Where are the differences between these two functions?
The general standard answers are:
Pconnect is a continuous connection, and PHP will duplicate the existing data library connections
But after that, there's a lot less people to say.
The usual suspects are:
When to use connect when to use Pconnect?
Mysql_close when to use?
Why is there a bunch of sleep process on the database?
Why do you use pconnect every time resource IDs are different?
To get back to the simplest explanation, Pconnect will check to see if there are any existing data library connections.
If so, use the old wiring, and if not, open a new connection.
But what you're saying here is checking the wiring, which is the data library connection that this Apache trip opened.
Instead of the data library connections that this Web server has opened.
There may be a hundreds apahe stroke on a Web server (2.0 preset max 150)
Which means that in the greatest case, there might be a data library connection hundreds pconnect.
(actually less than that)
So using Pconnect is a different resource ID.
Because he's probably doing it on a different schedule.
And Pconnect is not going to shut down after the search is done, but will wait a certain time
This time can be set by the wait_timeout on MySQL
And Mysql_close does not close the connection that Pconnect has opened, only to turn off the data library connection opened by connect. Of course, if there is no close, it will be dropped by DB after timeout time.
Pconnect must be careful to use, in the written bad code, will leave a large number of database CONNECTION. The maximum value can be calculated like this
Apache Trip number Per server * All Web SERVEWR numbers
Of course, I don't need to remind you that every connection consumes DB CPU time and memory
When you write a Web code, there are two points that must be answered before you use any language.
One is, what data to crawl from the database
And the second is, what is to be transferred to the user side
(In fact, this is not only used on the web)
Database connection is very slow, can crawl the required data at one time, do not divide the two