php.net |  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
Votes:1
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
Description:
------------
I am having the following issue with pconnect on my development box:

environment:
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.

testing:
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.

symtoms:
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:

127.0.0.1       localhost.localdomain   localhost
127.0.0.1       some.faroffserver.com

PHP app:

$db = mysql_pconnect('some.faroffserver.com', '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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 13:01:29 2024 UTC