Re: Exec Script in the background, don't wait till it finishes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 14, 2011 at 11:56, Kai Renz <writemecas@xxxxxxxxxxxxxx> 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/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux