irken Posted March 17, 2007 Share Posted March 17, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/43099-persistent-connections/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.