ID:               26490
 Updated by:       [EMAIL PROTECTED]
 Reported By:      chris dot noden at monstermob dot com
-Status:           No Feedback
+Status:           Open
 Bug Type:         MySQL related
 Operating System: Redhat AS 2.1
 PHP Version:      4.3.3
 New Comment:

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 ) 




Previous Comments:
------------------------------------------------------------------------

[2003-12-07 12:00:26] [EMAIL PROTECTED]

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.



------------------------------------------------------------------------

[2003-12-02 01:03:21] [EMAIL PROTECTED]

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try avoid embedding huge scripts into the report.





------------------------------------------------------------------------

[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

Reply via email to