On 29 Mar 2012, at 20:49, Ralf Gnädinger wrote:
> i got some trouble with a PHP script using pcntl_fork do run some work in
> background.
> Runnig my script on my development system (PHP version 5.3.3-7) it behaves
> like
> intended. But running it on my production test system (PHP version PHP
> 5.1.2), i got
> some strange results. The problem is, that when i logout from my SSH
> session the
> console closes not properly, like somethings is kept open. Sadly, updating
> this old PHP
> version is not a option... :/
>
> Does anyone have an idea whats going on?
>
> Thanks in advance
>
> Ralf
>
> The script is this:
>
> #!/usr/bin/env php
> <?php
>
> $pid = pcntl_fork();
> if ($pid == -1) {
> die('Fork failed!');
> } else if($pid > 0) {
>
> exit(0); // close parent process
>
> } else { // child process:
>
> while(true) {
> sleep(10);
> // do your work -- stripped
> }
> }
> ?>
>
> do not work with:
> PHP 5.1.2 with Suhosin-Patch 0.9.6 (cli) (built: Dec 12 2007 02:42:35)
> Copyright (c) 1997-2006 The PHP Group
> Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
>
>
> works with:
> PHP 5.3.3-7+squeeze3 with Suhosin-Patch (cli) (built: Jun 28 2011 08:24:40)
> Copyright (c) 1997-2009 The PHP Group
> Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
> with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
You need to detach the child from the terminal using posix_setsid(). I don't
know why it's "working" on your development machine, but it's probably simply
that you're not seeing this issue due to how you access that development
machine.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php