Bug #46740 [Opn->Csd]: PHP Not Cleanly Closing MySQL Connections on Apache Death

From: Date: Tue, 30 Dec 2014 20:53:20 +0000
Subject: Bug #46740 [Opn->Csd]: PHP Not Cleanly Closing MySQL Connections on Apache Death
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189549@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=46740&edit=1 ID: 46740 Updated by: jacob@php.net Reported by: php at matthewboehm dot com Summary: PHP Not Cleanly Closing MySQL Connections on Apache Death -Status: Open +Status: Closed Type: Bug Package: PDO MySQL Operating System: RHEL5.2 PHP Version: 5.2.9 -Assigned To: +Assigned To: jacob Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2012-05-04 15:38:19] justice dot libra dot boyz at gmail dot com [SOLVED] PROBLEM : http://www.php.net/manual/en/features.persistent-connections.php TO DO : php.ini >> mysql.allow_persistent = off ------------------------------------------------------------------------ [2012-05-04 14:47:19] justice dot libra dot boyz at gmail dot com yeah i found same problem using 5.2.9.9.. any patch from inside php engine guys? ------------------------------------------------------------------------ [2009-07-08 16:18:59] dmlance at gmail dot com Same problem with 2.2.11 and 5.2.10. Due high load on my server with croned scripts I got about 60% aborted connections in my logs. ------------------------------------------------------------------------ [2009-04-01 14:34:46] dstuff at brainsware dot org Got the same problem using PHP version 5.2.9 on Debian (Lenny) ------------------------------------------------------------------------ [2008-12-03 15:45:59] php at matthewboehm dot com 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 this bug report at https://bugs.php.net/bug.php?id=46740&edit=1

« previous php.bugs (#189549) next »