note 51217 added to function.pcntl-fork

From: Date: Wed, 23 Mar 2005 19:01:11 +0000
Subject: note 51217 added to function.pcntl-fork
Groups: php.notes 
Request: Send a blank email to php-notes+get-86855@lists.php.net to get a copy of this message
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); ---- Manual Page -- http://www.php.net/manual/en/function.pcntl-fork.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51217 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51217&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51217&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51217&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51217&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51217&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51217&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86855) next »