PHP's Pconnect ()

Source: Internet
Author: User
Tags connect mysql pconnect resource

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



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.