php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26117 Persistent connection not reused
Submitted: 2003-11-04 11:00 UTC Modified: 2003-11-19 18:25 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: spam at vrana dot cz Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.3.3 OS: Linux
Private report: No CVE-ID: None
 [2003-11-04 11:00 UTC] spam at vrana dot cz
Description:
------------
Configuration:
Apache 1.3.28
MySQL 4.0.15a

With Apache configuration directive MaxClients set to 150, the number of database connection raised up to 466 (until MySQL denied connections with Too many connections error). In all scripts I use the same mysql_pconnect("localhost", "user", "pwd").

MySQL command SHOW PROCESSLIST showed that all 466 connections were made with the same connection parameters. All connections were in state Sleep.

I am connecting to MySQL only from PHP module in Apache so I think this behavior is caused by some bug in handling with connection pool in PHP.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-04 13:53 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

If you go mysql_select_db() then the persistent connection you've created becomes specific to that particular database. Which may explain why those connections are not re-used.
Also, persistent connections are per-child, meaning that if 1 Apache child opens connections only that child has a pre-existing connection avaliable. If a subsequent request is handled by another child, which does not yet have a MySQL connection, it'll create a new connection.
 [2003-11-05 03:24 UTC] spam at vrana dot cz
This is not the case. Believe me that I have read all similar bugs and this is different. I also have read carefuly the manual and I understand everything written there about persistent connections.

There is written in the Persistent Database Connections chapter of manual: An 'identical' connection is a connection that was opened to the same host, with the same username and the same password (where applicable). So it's not true that by mysql_select_db() with different database name the connection can't be reused. Anyway I use the same database in all scripts.

I know that connection is persistent only over the child. Thus I wrote that Apache configuration directive MaxClients is set to 150.
 [2003-11-05 11:21 UTC] iliaa@php.net
When the "too many connections" problem occurs, have you tried running "show full processlist;" query to see if infact all connections use the same database?
 [2003-11-05 12:20 UTC] spam at vrana dot cz
Yes. There were 466 processes with the same user, host and db. All processes were in state Sleep.
 [2003-11-17 18:21 UTC] sniper@php.net
And this is PHP bug in where..?

 [2003-11-18 07:33 UTC] spam at vrana dot cz
Can you please read my bug report carefuly before stating bug as bogus? Persistent connection in PHP should reuse previous persistent connection with the same host, user and password. The bug is that it doesn't.
 [2003-11-18 15:07 UTC] sniper@php.net
Well, it does work fine for me. 

 [2003-11-19 04:03 UTC] spam at vrana dot cz
Do you think that there is no problem if it works for YOU and doesn't work for others?
 [2003-11-19 18:25 UTC] sniper@php.net
I have mysql 4.0.16 on one machine, 3.23.53 in one and 3.23.49 in another. And all of these work just fine.

So I think it's rather a problem in your script(s) or bug in that mysql version you're using or your configuration.

I did a quick test with setting MaxClients to 10 and run
# ab  -n 1000 -c 100  http://localhost/test.php

(where test.php does rather heavy queries, several of them)

And only error I got was:

[Thu Nov 20 01:19:33 2003] [error] server reached MaxClients setting, consider raising the MaxClients setting

(And that's an Apache error..)

My other settings are the default ones for Apache and mysql and php.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 11:01:31 2024 UTC