ID:               23649
 Comment by:       chris dot noden at monstermob dot com
 Reported By:      sthomas at townnews dot com
 Status:           Bogus
 Bug Type:         MySQL related
 Operating System: Redhat Linux 9.0
 PHP Version:      4.3.2RC2
 New Comment:

PHP 4.3.3 on RedHat Advanced Server 2.1

I get a similar problem.  The forked (child) process loses the
connection the MySQL - apparently during a pcntl_waitpid from the
parent.

eg. - all running in CLI mode:
A PHP script forks a child (or many) which go off (reconnecting to
MySQL first) and do their stuff.  The parent (original) PHP script
periodically checks on the status of the children using pnctl_waitpid
querying each child pid in turn using the WUNTRACED option (WNOHANG
does not work very well leaving defunct children everywhere).

Sometimes (not always) the child process is disconnected from MySQL and
I can't seem to sort it out.  Have tried many workarounds.

The MySQL error is 2013 - Lost connection to MySQL server during
query.

Sometimes (less often) the mysql_fetch_array and mysql_num_rows can
also fail after a succesful query, assuming that this is caused by the
same thing - MySQL being disconnected.


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

[2003-05-30 14:39:40] [EMAIL PROTECTED]

You can't use same connection. You have to establish a new connection
inside the forked process.

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

[2003-05-16 08:40:59] sthomas at townnews dot com

Actually yes, it does.  The fork itself seems to be causing this.  All
I have to do to see that is comment out the fork/exit and it works just
fine.  Unfortunately one of our crazy developers wrote a daemon that
maintains a connection to our database and distributes it to child
forks to avoid innundating our DB with connections, so this is really
screwing us.  It still does this at least all the way back to PHP 4.3.0
- as that's what we're running in production and where we first noticed
this.

And I'm not sure it's related, but the PHP 4.3.0 version would print
the "This is before the fork!" twice, as if the child was running the
whole script.  It doesn't do this in PHP 4.3.2RC2, but after doing a
diff to the pcntl code between those versions, there are no
differences.  I can't personally see how internals would affect the
forking model, so I don't know what's going on.  I can provide you with
a strace if you need it - since I can't get a backtrace.

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

[2003-05-15 18:51:41] [EMAIL PROTECTED]

Does this work if you don't have pcntl_fork() there?




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

[2003-05-15 17:41:58] sthomas at townnews dot com

To reproduce, simply run this script from the PHP CLI:

<?PHP
print "This is before the fork!\n";

mysql_connect('remote.host', 'user', 'pass');
mysql_select_db('database');

print "Query 1:";
mysql_query('select 1');
print mysql_error();
print "\n";

if (pcntl_fork())
  exit();

print "Query 2:";
mysql_query('select 1');
print mysql_error();
print "\n";

mysql_close();
?>

This will almost always produce a "Lost connection to MySQL server
during query" error for the second query.  Though I did notice that it
seems to happen only if the host is a remote host.

We are using PHP 4.0.12 as the server, and this bug seems to occour
whether we use the included mysql client libraries or compile against
the 4.0.12 libraries.


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


-- 
Edit this bug report at http://bugs.php.net/?id=23649&edit=1

Reply via email to