ID: 26490 Comment by: Ryan dot Springer at billingconcepts dot com Reported By: chris dot noden at monstermob dot com Status: Verified Bug Type: MySQL related Operating System: * PHP Version: 4CVS, 5CVS (2004-03-13) New Comment:
Is everyone who is effected by this bug running Red Hat? If so, this may be a libc problem. See: http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=75128 Previous Comments: ------------------------------------------------------------------------ [2004-03-11 11:39:40] [EMAIL PROTECTED] This happens on the following versions: php 4.3.3, 4.3.4, 4.3.5RC3 with bundled or external mysql client code with shared or buildin MySQL Server Version here is 4.0.18 The MySQL Log shows this row on a 'connection lost' error: Aborted connection 2048 to db: [....] (Got an error reading communication packets) ------------------------------------------------------------------------ [2004-03-11 11:35:27] [EMAIL PROTECTED] Since i just stumbled across the very same problem, i wrote a small (?) testcode to check it. It seems like using pconnect in favor of a 'normal' connect fixes the problem for the testcode, while it does not for my reallife application. The code assumes a database with at least 100 rows. Structure as follows: CREATE TABLE debug2 ( ID int(11) NOT NULL auto_increment, CODE varchar(10) NOT NULL default '', PRIMARY KEY (ID), ) TYPE=MyISAM This is the testcode, run it from cli ;) <?php function do_something($ppid,$data) { $db=mysql_connect('db.local.dev','dev','dev'); echo mysql_error(); mysql_selectdb('fpostv4',$db); echo mysql_error(); foreach ($data as $row) { $sql="update debug2 set CODE='1' where ID='{$row['ID']}'"; echo "[$ppid] $sql\n"; $rc=mysql_query($sql); echo mysql_error(); } } $db=mysql_connect('db.local.dev','dev','dev'); mysql_selectdb('fpostv4',$db); echo mysql_error(); $rc=mysql_query('update debug2 set code=""'); echo mysql_error(); $rc=mysql_query('select * from debug2'); echo mysql_error(); for ($t=0; $t<10; $t++) { $pid = pcntl_fork(); if ( $pid == -1 ) { die('Error during fork() - halting'); } elseif ( $pid == 0 ) { $ppid=getmypid(); mysql_data_seek($rc,$t*10); echo mysql_error(); for ($x=0; $x<10; $x++) { $data[]=mysql_fetch_assoc($rc); } do_something($ppid,$data); die(); } else { $pidlist[]=$pid; $sendPos += $perThread; } } // wait for them to finish... while (count($pidlist)) { foreach ($pidlist as $key => $ppid) { $tmp=pcntl_waitpid($ppid, $temp, WNOHANG); if ($tmp!=0 ) { unset($pidlist[$key]); } } sleep(2); } ?> You may have to run the code multiple times to actually see the problem. The "Lost connection" error doesn't occur on a fixed rate or value. You may be 'lucky' and don't hit it at all in a run.. Feel free to contact me in irc ( freenode / ircnet ) ------------------------------------------------------------------------ [2003-12-01 13:16:29] chris dot noden at monstermob dot com Description: ------------ MySQL version 4.0.13 running on a different server on the LAN using pconnect: After using a pcntl_fork() the child thread suffers from the "2013 : Lost connection to MySQL server" error above. I can continue to use the MySQL connection without connecting again implying that the connection has miraculously re-established itself! The error can occur at any stage in a query, (eg during submission or reading the results of the query). The error usually manifests itself when the query returns no results. The error comes from the parent process!! I have tried all sorts of workarounds, to no avail. Reproduce code: --------------- do { $sql = "SELECT stuff FROM db WHERE a=b"; $qryID = mysql_query($sql,$Link_ID while (mysql_fetch_array($qryID)) { // Fork off a child $is_parent = pcntl_fork(); if ($is_parent > 0) { // I am the child - do some stuff exit; } else { // I am the parent do some stuff } // end if/else sleep(1); } while (condition); Expected result: ---------------- Normal database flow. Actual result: -------------- Error 2013 - Lost connection to MySQL server during query ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=26490&edit=1