Re: Exec Script in the background, don't wait till it finishes
| From: | Daniel Brown | Date: | Fri, 14 Jan 2011 18:19:42 +0000 |
| Subject: | Re: Exec Script in the background, don't wait till it finishes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-310766@lists.php.net to get a copy of this message | ||
On Fri, Jan 14, 2011 at 11:56, Kai Renz <writemecas@googlemail.com> wrote:
>
> Now here is the problem:
> it all works fine, but the client can't send a quit message to socket1
> because socket1.php waits until socket2.php is finished. socket2.php
> is working properly, and if i connect to the new socket and quit the
> connection, socket1 is working again. All i need socket1 to do is to
> continue working independant of socket2.
>
> I tried everything, from shell_exec to pcntl_exec, nothing seems to work.
Have you looked into pcntl_fork() or running it in the background
via something as simple as backticks? The latter of which,
exemplified:
<?php
/bin/env php /path/to/socket2.php --port 1234 >> /path/to/log.txt 2>&1
&;
?>
Expanding on that, you could do something like this:
<?php
exec('/bin/env php /path/to/socket2.php --port 1234 >>
/path/to/log.txt 2>&1 &',$ret,$err);
if ($err === 0) {
exec('echo $$',$ret);
$pid = $response[0];
echo $pid.PHP_EOL;
} else {
echo 'There was an error while forking the process. Please
view the log.'.PHP_EOL;
}
?>
--
</Daniel P. Brown>
Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/