Now: Tutorial for Web and Software Design > PHP > QA > PHP Content
> PHPFAQ - Whats the difference between the *connect and *pconnect database functions? [Bookmark it]
PHPFAQ - Whats the difference between the *connect and *pconnect database functions?


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.

[Bookmark][Print] [Close][To Top]
  • Prev Article-PHP:

  • Next Article-PHP:
  • Related Materias
    PHPFAQ - How google is you
    PHPFAQ - Are there any web
    PHPFAQ - How can I accept 
    PHPFAQ - How can I finance
    PHPFAQ - Where can I get P
    PHPFAQ - Where can I host 
    PHPFAQ - Where can I find 
    PHPFAQ - I am trying to cr
    PHPFAQ - Is there a librar
    PHPFAQ - How can I manage 
    Topics
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Graphic Design Tutorial
     

    Coreldraw Tutorial

      Illustrator Tutorial
      3D Graphics Articles
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial&Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial&Articles
     

    XML Style Tutorial

      AJAX Tutorial
      XML Mobile
    Flash Tutorial&Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial&Articles
     

    Linux Tutorial

      Symbian Tutorial
      MacOS Tutorial