ID:               26490
 Comment by:       angel at support-24 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:

I have this issue only while crawling something. 
For example I have 50 000 curl requests to a page. I crawl the page,
gather info and store it in a database, only if the page contains what
I'm looking for.

I have noticed that in about every 50 queries the mysql insert query
crashes with this error: Lost connection to MySQL server during query

System is: Windows XP, Apache 2.2 MySQL 5.0


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

[2007-05-23 06:38:50] david at ols dot es

I have the same problem with php 4.4.4, from time to time
both pconnect and connect fail with error " Lost connection to MySQL
server during query", but only when using a mysql server on a remote
machine, never when using local sockets

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

[2006-12-15 15:46:37] 18sanny at azet dot sk

If this image is hard to read, reload the page.

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

[2006-08-10 21:52:54] mcote at voyagesconstellation dot com

Same problem, sometimes!  But if we keep trying we usually get result
in 2-3 tries, this code works to keep trying without hanging forever!

$result = FALSE;
$counter = 0;
while($result==FALSE)
{
  $res = mysql_query($waitquery);
  $result = mysql_fetch_assoc($res);
  $counter++;
  error_log("error happened! - mysql Connection was lost!! 
try#$counter);
  if ($counter==5)//prevents major major hang! ;-)
    break;
}

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

[2005-04-14 19:16:15] Andreas dot Oesterhelt at InTradeSys dot com

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).

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

[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

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

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

Reply via email to