note 51217 deleted from function.pcntl-fork by nlopess
| From: | nlopess@php.net | Date: | Sat, 22 Jul 2006 11:39:59 +0000 |
| Subject: | note 51217 deleted from function.pcntl-fork by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-115043@lists.php.net to get a copy of this message | ||
Note Submitter: reinoud at hyves dot nl
----
Note that (among other things ?) your mysql resources need to be closed neatly before doing a
pcntl_fork. If not, you might have mysql_query return false with errno=0 and no error message - even
if the child doesn't touch the database at all. So I ended up using the following code:
$database_resource=mysql_connect($server,$port, $dbuser, $dbpass);
someCodeWhichDoesSomeQueries($database_resource);
mysql_close($database_resource);
if (pcntl_fork() === 0)
{
$database_resource=mysql_connect($server,$port, $dbuser, $dbpass); //obviously you only add this
if the child is going to interact with the database
executeChildCode($database_resource);
exit();
}
$database_resource=mysql_connect($server,$port, $dbuser, $dbpass);
executeParentCode($database_resource);