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

    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:

    Code:
    |Id|User|Host|db|Command|Time|Info
    |1098|test|dns1.xxxxxx.com:40219|test|Sleep|7581|NULL
    |1099|test|dns1.xxxxxx.com:40220|test|Sleep|7579|NULL                                                                
    |1100|test|dns1.xxxxxx.com:40221|test|Sleep|7581|NULL
    |1101|test|dns1.xxxxxx.com:40222|test|Sleep|7585|NULL
    |1103|test|dns1.xxxxxx.com:40224|test|Sleep|7586|NULL
    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!

    Aaron

  2. #2
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    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
    Posts
    19
    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:
    <?php
        
        $db 
    '';
        
    $db mysql_pconnect('192.168.2.70''test''*****');
        
        
    mysql_select_db('test'$db);
        
    $query "SELECT * FROM ReplicationTesting";
        
    $result mysql_query($query) or die (mysql_error());
        
        
    mysql_close();
        
    ?>
    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
  •