Bug #23649 [Nab->Csd]: Lost connection to MySQL server during query after pcntl_fork

From: Date: Tue, 06 Apr 2021 10:40:41 +0000
Subject: Bug #23649 [Nab->Csd]: Lost connection to MySQL server during query after pcntl_fork
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233206@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=23649&edit=1 ID: 23649 Updated by: git@php.net Reported by: sthomas at townnews dot com Summary: Lost connection to MySQL server during query after pcntl_fork -Status: Not a bug +Status: Closed Type: Bug Package: MySQL related Operating System: Redhat Linux 9.0 PHP Version: 4.3.2RC2 Block user comment: N Private report: N New Comment: Automatic comment on behalf of roojs Revision: https://github.com/php/pecl-tools-svn/commit/aa7ec08152201302dd89da709b2ccdbf4115c27a Log: fix #23649 - allow deletion of properties by using NULL as value (patch by Jonas Zeiger) Previous Comments: ------------------------------------------------------------------------ [2003-11-29 10:23:57] chris dot noden at monstermob dot com 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. ------------------------------------------------------------------------ [2003-05-30 14:39:40] georg@php.net 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] sniper@php.net 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 https://bugs.php.net/bug.php?id=23649&edit=1

« previous php.bugs (#233206) next »