Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2004

    Unanswered: Trying to Figure Out Persistent Connections

    It is my understanding that when using mysql_pconnect (PHP), the server will attempt to find a connection with the identical hostname, username, and password before creating a new connection.

    To test this, I created a simple script that connects to the database, runs a query and the closes the connection (mysql_close()). I then loaded this script and hit the refresh button 5 times in a row (with a slight pause between each).

    I then ran "show full processlist;" and found that 5 separate connections had been created:

    Is this the correct behavior? I thought that because it was the same script, it would reuse a single connection. Am I wrong?

    Thanks for any advice!


  2. #2
    Join Date
    Apr 2006
    Denver, Co. USA
    Show us your test script so that someone here can see if there is a problem with it.

    If you are using a persistent connection, calling mysql_close() has no effect.

    There is a restriction on using pconnect, the web server must be multiprocess (php must be running as an Apache module or an IIS ISAPI module) and not as a single thread under CGI.

  3. #3
    Join Date
    Sep 2004
    There should be no problems with the script... as I mentioned, it is very basic. Only the minimal code to recreate the problem...

    PHP Code:
    $db mysql_pconnect('''test''*****');
    $query "SELECT * FROM ReplicationTesting";
    $result mysql_query($query) or die (mysql_error());
    Apache is running PHP using mod_php, so there shouldn't be any problems there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts