Jump to content

Persistent connections


irken

Recommended Posts

Hello.

 

Correct me if I'm wrong, but isn't a persistent mysql connection supposed to return the previous connection resource once I do mysql_pconnect() again, with the same parameters?

 

Here's my very simple test class..

 

<?php

  class Mysql { 

    var $hostname = 'localhost';
    var $username = 'gateway';
    var $password = '';
    var $database = 'somedatabase';

    var $connection = NULL; 
    
    public function __construct() { }

    public function connect() {

      if (!$this->connection) {
        $this->connection = mysql_pconnect($this->hostname, $this->username, $this->password);
        mysql_select_db($this->database);
        return $this->connection;
      }

      // resource exists ?
      return $this->connection;
    }
    
  }
  
?>

 

And some test script

<?php
  include('mysql.php');

  $myMysql = new Mysql;
  $myMysql->connect();
?>

 

 

Acording to mysql's SHOW processlist the result is this:

mysql> show processlist;

 

+-----+---------+-----------+----------------+---------+------+-------+------------------+
| Id  | User    | Host      | db             | Command | Time | State | Info             |
+-----+---------+-----------+----------------+---------+------+-------+------------------+
| 151 | root    | localhost | NULL           | Query   |    0 | NULL  | show processlist |
| 159 | gateway | localhost | somedatabase | Sleep   |  984 |       | NULL             |
| 160 | gateway | localhost | somedatabase | Sleep   |  963 |       | NULL             |
| 161 | gateway | localhost | somedatabase | Sleep   |  809 |       | NULL             |
| 162 | gateway | localhost | somedatabase | Sleep   |    3 |       | NULL             |
+-----+---------+-----------+----------------+---------+------+-------+------------------+
5 rows in set (0.00 sec)

 

As you can see there are 4 connections? This is from refreshing the test.php script 4 times. Am I to undertand that it's pooling up connections and when it reaches max, it will return one of them to the PHP script?

 

Thanks for reading.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.