note 16496 deleted from function.mysql-pconnect by jimw

From: Date: Fri, 02 Nov 2001 00:20:27 +0000
Subject: note 16496 deleted from function.mysql-pconnect by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20030@lists.php.net to get a copy of this message
This is gonna be a little long... I just setup mysql master/slave replication and its very cool; except that pconnect does have an issue that caused me a lot of very interesting problems today. Here is the situation, and oddly enough, a simple solution: If you have: ###################################################### $DB_hostname = "writeDB.here.com"; function MY_QUERY ($database, $query) { global $DB_hostname, $DB_username, $DB_password, $DB_name; ## here's the conditional!!! ## if we're "selecting", use the "read" (slave) server if (substr($query, 0, 6) == "SELECT") { $DB_hostname = "readDB.here.com"; } MYSQL_PCONNECT ($DB_hostname, $DB_username, $DB_password) OR DIE("unable to connect"); @mysql_select_db ($database) or die ("Unable to select database - $database"); $result = MYSQL_QUERY ($query); return ($result); } ###################################################### if the conditional to reset $DB_hostname is TRUE and the new hostname is set and then used in the Pconnect, statement, $DB_hostname is permanantly set within that HTTPD child to "readDB.here.com". It will never return to the globally defined value ever again "writeDB.here.com". So, just to try it, I added: $DB_hostname = "writeDB.here.com"; just before the return(); statement at the end of the function and the problem goes away. never seen anything like that before. :-) PHP certainly doesn't act that way with other variables in other functions. I did not take the time to test this with mysql_connect. Regarding the existing debate, aside from this issue, my experience has shown that pconnect is far better. *shrug* FYI, we're doing about 65 queries per second on average (which I now have setup between master/slave DB servers); I have my max connections on MySQL set @ 500.

« previous php.notes (#20030) next »