|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31782 Database selection fails intermittently with pconnect
Submitted: 2005-01-31 18:23 UTC Modified: 2005-02-08 17:32 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: brian dot sanders at cometsystems dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.0.2 OS: Fedora Core 3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: brian dot sanders at cometsystems dot com
New email:
PHP Version: OS:


 [2005-01-31 18:23 UTC] brian dot sanders at cometsystems dot com
I am having the following issue with pconnect on my development box:

I have an entry in my /etc/hosts file to point the hostname of a remote MySQL server to localhost.  This allows me to test the production setup, while running both the application and database on my local machine.

I can connect as the application user via the mysql client to the local database by either 'localhost' or by the remote name (which is looped back to 'localhost.localdomain', as described above.)  I can select the database 'use my_db' repeatedly without failure.

My PHP app uses mysql_pconnect() to connect to the remote database server (again, which is looped back to 'localhost.localdomain'.)  Intermittenly, PHP connects to the server, but fails to select the database.  Unlike bug #24977, mysql_select_db() does return false (as it should.)

This issue seems to be tied to the persistant connections.  mysql_select_db() might fail 5-20 times, then work 5-20 times, then fail again.  Strangely enough, the app never fails to connect, but only to select the database.  If I change mysql_pconnect() to mysql_connect(), the problem disappears.  Also, if I change the app's configuration to connect to localhost.localdomain (instead of the looped-back remote address) the problem disappears.

So to sum up, using mysql_pconnect() to connect to a non-localhost hostname on the local machine causes mysql_select_db to fail intermittenly.

Here's the info on my box:
OS: Fedora Core 3
kernel: 2.6.10-1.741_FC3smp
MySQL server: 3.23.58
MySQL client: Ver 11.18 Distrib 3.23.58, for redhat-linux-gnu (i386)
Apache: 1.3.33 built from source
PHP: 5.0.2 built from source

Reproduce code:
/etc/hosts:       localhost.localdomain   localhost

PHP app:

$db = mysql_pconnect('', 'user', '');
if(!$db) {
    die('Could not connect to database');
} else {
    if(!mysql_select_db('my_db', $db)) {
        die('Could not select database.');

Expected result:
Nothing (mysql_select_db() returns true)

Actual result:
Sometimes mysql_select_db() returns false.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-08 17:32 UTC] brian dot sanders at cometsystems dot com
I have not been able to reproduce this since me last update to PHP, so I am closing it for now...
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Oct 04 19:01:25 2023 UTC