note 24573 added to function.pcntl-fork
| From: | kingmundi at hotmail dot com | Date: | Wed, 21 Aug 2002 21:34:02 +0000 |
| Subject: | note 24573 added to function.pcntl-fork | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35321@lists.php.net to get a copy of this message | ||
Regarding the
'Call to undefined function: pcntl_fork() in...'
You have to configure pcntl before building php.
It apparently only works when you make the
standalone php binary. I have built such a
standalone binary and gotten the daemon
process to work. Example...
#!/usr/local/bin/php -q
<?
function daemonize()
{
$pid = pcntl_fork();
if ($pid == -1)
die("could not fork");
else if ($pid)
exit(); //we are the parent
return $pid;
}
if(daemonize() == 0)
{
if(daemonize() == 0)
{
//do daemon work here
//just a dummy loop to keep it running
while(1)
$x++;
}
}
?>
now from a command line you can run it
(if you have the file saved as daemon.php)
./daemon.php
and it will spawn off a new process.
However, I can not figure out why if you call
the script from a webpage script using the
system() or exec() functions like so
<?
system("/var/somewhere/daemon.php");
?>
The page sits and sits and waits for the
function to finish before it is done loading the
page. Very different behaviour from running
it from the command line.
You can of course manually stop loading the
page (and the daemon.php program is still
running as a process on the server). It is as
though the parent process is the apache mod
php and it is waiting on its child (the
daemon.php) except I thought doing a double
fork would prevent this.
--
http://www.php.net/manual/en/function.pcntl-fork.php
http://master.php.net/manage/user-notes.php?action=edit+24573
http://master.php.net/manage/user-notes.php?action=delete+24573
http://master.php.net/manage/user-notes.php?action=reject+24573