Home >Backend Development >PHP Tutorial >php pconnect_PHP tutorial

php pconnect_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:26:541434browse


What is the difference between PHP’s two functions FUNCTIONCONNECT and PCONNECT when connecting to MYSQL? The general standard answer is: PCONNECT is a persistent connection, and PHP will reuse the existing database connection
But if you ask further, fewer people can tell. Many common questions include: When When to use CONNECT, when to use PCONNECT? When to use mysql_close? Why are there a bunch of SLEEP PROCESS on DATABASE? Why is the RESOURCE ID different every time when using PCONNECT?
Returning to the simplest explanation first, pconnect will check whether there is an existing database connection. If there is, use the old connection; if not, open a new connection. But the check connection mentioned here refers to the database connection opened by this APACHE process and not by this WEB SERVER. database connection. There may be hundreds of APAHE processes on a WEB SERVER (2.0 defaults to a maximum of 150), which means that in the maximum case there may be hundreds of database connections caused by PCONNECT (actually it will be far less than this), so When using PCONNECT, different RESOURCE IDs will appear because it may be executed on different itineraries
and PCONNECT will not be closed after the query is completed, but will wait for a certain period of time. This time can be set by wait_timeout on MYSQL. Moreover, mysql_close cannot close the connection opened by pconnect, but can only close the database connection opened by connect. Of course, if there is no CLOSE, it will be DROPed by DB after the TIMEOUT time has passed.
PCONNECT must be used with caution. A large number of DATABASE CONNECTIONs will remain in poorly written CODE. The maximum value can be calculated like this: The number of APACHE trips for each SERVER* Of course, I don’t need to remind you of the number of all WEB SERVEWRs. Each connection will consume the DB’s CPU TIME and MEMORY
When writing WEB CODE, no matter what language is used, There are two points that must be answered before starting to write. One is, what data should be captured from DATABASE, and second, what data should be sent to the USER end (in fact, this is not only used for WEB). The connection of DATABASE is very slow. If you can capture the required information in one go, don’t do it twice

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531915.htmlTechArticlePHP has two functions FUNCTIONCONNECT and PCONNECT when connecting to MYSQL. What is the difference between these two functions? The general standard answer is: PCONNECT is a persistent connection, and PHP will reuse existing connections...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn