From:             php at matthewboehm dot com
Operating system: RHEL5.2
PHP version:      5.2.6
PHP Bug Type:     Apache2 related
Bug description:  PHP Not Cleanly Closing MySQL Connections on Apache Death

Description:
------------
When using PHP/MySQL with persistent connections, upon the death of 
an apache child, you get an 'aborted connection' message inside the 
MySQL server's error log.

In my supremely most humbled opinion, I can only presume that PHP is 
not cleanly closing opened MySQL connections when an apache child 
dies and the PHP module is unloaded from apache's memory.

Reproduce code:
---------------
To reproduce:

 1. Start httpd (I used 2.2.10) with PHP 5.2.6. httpd should use the
prefork MPM with the following settings on the MPM:
    StartServers           5
    MinSpareServers        5
    MaxSpareServers       10
    MaxRequestsPerChild 1000

 2. Browser the following PHP file several times to initiate several
persistent connections to your MySQL database. This can be either of the
MySQL methods that support persistence. (mysql_pconnect, and PDO)

<?php
try
{
        $dbh = new PDO('mysql:host=DBHOST;dbname=DBNAME', 'DBUSER',
'DBPASS', array(PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE =>
PDO::ERRMODE_EXCEPTION));

        if($res = $dbh->query("SELECT * FROM myTable"))
        {
                print "Query success";
        }
        else
        {
                print "Query failed";
        }
}
catch(PDOException $e)
{
        echo 'Error: ' . $e->getMessage();
}

3. Stop apache via any means. You will see in your MySQL log 1 aborted
connection line for each terminated apache process.

In my testing, I used 'ab' to throw 10,000 requests of the above code at
apache. Every 1000 requests, I would see the error in MySQL. This is
because of the MaxRequestsPerChild setting to be 1000. Every 1000, an
apache thread will suicide and then spawn a new thread.

Once the load test was complete, if more than MaxSpareServers threads
where running, apache would kill them off as well and you would see that
same number of errors in MySQL.

Expected result:
----------------
I would not expect to see any errors from MySQL. I would expect all 
connections to be properly closed upon the death of an apache 
process.

Actual result:
--------------
The actual result is an incorrectly closed MySQL connection.

-- 
Edit bug report at http://bugs.php.net/?id=46740&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=46740&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=46740&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=46740&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=46740&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=46740&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=46740&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=46740&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=46740&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=46740&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=46740&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=46740&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=46740&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=46740&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=46740&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=46740&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=46740&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=46740&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=46740&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=46740&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=46740&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=46740&r=mysqlcfg

Reply via email to