Alt-PHP-Faq
PHP4,PHP5 and PHP6 Hosting


Question :

What's the difference between the *connect and *pconnect database functions?

Answer :
from http://www.php.net/manual/en/function.mysql-pconnect.php :

--
mysql_pconnect() acts very much like mysql_connect() with two major differences.

First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).

These type of links is therefore called 'persistent'.

--

I think that's a pretty good explanation myself.

basically, use pconnect when you're going to be using the same host a lot, but otherwise there's no real need. as Steve Yelvington said in a post a while back ():

--
A persistent connection is potentially shared by serial invocations of your application ... but you don't need to know about it. If a connection already exists to the same database with the same username and password, PHP will take advantage of it automatically. If not, PHP will open such a connection and leave it open in hopes of using it again.

Now, stop and consider whether you really want to do this.

A persistent connection comes with benefits AND costs. The benefit (not having to reconnect to MySQL) comes at the cost of eating memory and -- importantly -- tying up MySQL connections.

Persistent connections make a lot of sense for a high-volume application on a Web server that has a fairly narrow purpose. Persistent connections do not make sense for low-volume applications on machines that are shared by many other applications (which probably describes your Web site on a shared host).

On a machine shared by many Web sites hitting a common MySQL server, persistent connections could backfire by locking out other users.

Categories Return to Main PHP Faq

Code

 

Questions

Code
How do I get a user's IP address?
How do I generate a random number from php?
How can I send variables from a PHP script to another URL using POST without using forms and hidden variables?
How do I insert javascript in php code?
How can I create thumbnails using PHP?
Can I create PDF files from php?
Is it possible to send HTML mail with php?
How can I use PGP with PHP?
I keep getting "headers already sent" whilst trying to use sessions
How do I user authentication in php?
How do i upload files from php to my ISP / server?
How do I format a number correctly?
How do I set the browser timeout?
How can I create random passwords?
Is there a way to encrypt text from php?
How can I limit search results so that there is a "Next 10" and "Previous 10"?
How can I protect pages using MySQL and PHP?
How do I find out weather a number is odd or even?
How to count number of parameters given in URL by POST?
How do I check whether a string contains HTML?
How to output a number with leading zero's?
Is it possible to spell check texts from php?
Does anyone know some URLS for good tutorials on PHP?
How do I get the total size of a certain directory?
How to access a COM object from within my PHP page?
How can I do error handling in php?
How can I get the DNS servers of a domain name?
How do I work with dates in php?
How do I make links on mail and www links on my pages?
Is it possible to connect to a ftp server with php?
Is it possible to validate an e-mail in php?
Using Curl can I access the OpenSRS admin control panel (tucows)
I keep getting "Data Missing" when I click the "back" button in my browser. How can I stop this?
How can I mail the content of a form?
I have an array of values and want to show them all reccursivly how?
How do I find out if an array has values posted to each of its elements? I need to know that EVERY element has been filled out.
Use ereg_replace to replace only the first occurence of a string instead of all?
How do you colour code the source in the answers on alt-php-faq.org?
I have upgraded to PHP-4.0.5, since doing that some of my scripts are just showing the source code?
 

Return to the main FAQ list




Free Forum     Forex
Dating for Men
Weight Loss
fitness
Design & Layout Copyright © 2000- 2008 PHP MySQL Web Hosting Comments to Webmaster
Hosted by PHP 4 Hosting - PHP and MySQL Webhosting and Domain Names