ID: 26490 Comment by: Andreas dot Oesterhelt at InTradeSys dot com Reported By: chris dot noden at monstermob dot com Status: No Feedback Bug Type: MySQL related Operating System: * PHP Version: 4CVS, 5CVS (2004-03-13) New Comment:
After further thinking at least my test case and Chris' original case are non-bugs: The child inherits the parent's open connection. When it dies, all its open files, including the (unused) inherited connection are closed. If the parent subsequently calls mysql_query() on that closed connection, a new one will be opened. But if the child termination happens while the parent is executing a query, the parent indeed loses its connection during its query. Sorry for wasting your time, --Andreas PS: Fork logic in testcase script was flawed, too. Should have been: if (!$is_child). Previous Comments: ------------------------------------------------------------------------ [2005-04-14 16:38:01] Andreas dot Oesterhelt at InTradeSys dot com As requested by theseer @php.net I'm adding a test case that steadily reproduces the problem for me. Both on a Single CPU Pentium 4, Linux 2.4.29, PHP 4.3.10, MySQL 4.1.10, libc 2.2.5 machine, as well as on a four CPU Ultra Sparc, Linux 2.4.27, PHP 4.3.10, MySQL 4.1.10a, libc 2.3.2 box I get the same results. The proposed workaround doesn't change that behaviour. The example code assumes there is a database testcasedb, to which a user testcaseuser on localhost using testcasepw has access. It needs to contain a table like this, although the table type really doesn't seem to matter: CREATE TABLE `testtable` (`row1` varchar(40) NOT NULL default '', `tstamp` timestamp NULL default NULL) DEFAULT CHARSET=latin1 ; <?php $dbres = mysql_connect('localhost', 'testcaseuser', 'testcasepw'); $parent_sql = "INSERT INTO testcasedb.testtable VALUES ('some test', now())"; $child_sql = "DELETE FROM testcasedb.testtable WHERE row1 = 'some test'"; do { for ($i = 1; $i <= 20; $i++) { print("Parent query starts\n"); if (!mysql_query($parent_sql, $dbres)) { print("Parent Mysql Error: " . mysql_error($dbres) . "\n"); } } $is_child = pcntl_fork(); if ($is_child > 0) { print("Child connection and query start\n"); $dbres = mysql_connect('localhost', 'testcaseuser', 'testcasepw', true); if (!mysql_query($child_sql, $dbres)) { print("Child Mysql Error: " . mysql_error($dbres) . "\n"); } exit; } print("Parent next iteration\n"); } while (true); ?> Basically the parent process loops forever, spawning children that each open a connection of their own, do a query and then die. You'll see that the parent will report Lost connections soon, although the children are doing their best not to reuse the parent's connection. Hope this helps to deeper look into the issue. Thanks for listening, --Andreas ------------------------------------------------------------------------ [2004-10-01 01:00:02] php-bugs at lists dot php dot net No feedback was provided for this bug for over a week, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". ------------------------------------------------------------------------ [2004-09-23 12:05:07] [EMAIL PROTECTED] Due to people claiming the "workaround" doesn't fix their problems, the bug is reopened. Please provide detailed feedback on how to reproduce the problem. ------------------------------------------------------------------------ [2004-09-22 21:06:23] tru at gtwreck dot com All you need to do is check out this query on google, and you can see that a lot of sites have this issue while google is indexing them... http://www.google.com/search?hl=en&lr=&ie=UTF-8&q=%22Lost+connection+to+MySQL+server+during+query%22+mysql_connect ------------------------------------------------------------------------ [2004-09-22 21:03:00] tommy at allstardirectories dot com The suggested work-around does not work for me. I'm still seeing intermittent connection losses (About 5-10 per day). ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/26490 -- Edit this bug report at http://bugs.php.net/?id=26490&edit=1