ID:               30539
 User updated by:  toppi at kacke dot de
 Reported By:      toppi at kacke dot de
-Status:           Feedback
+Status:           Open
 Bug Type:         *General Issues
 Operating System: Fedora Core 2 Linux
 PHP Version:      5.0.2
 New Comment:

Hi Tony,

it doenst work.

STDIN is not defined/open. When i understood the manual correctly, its
only defined when using cli sapi.

I have 
php -v
PHP 5.0.2 (cgi) (built: Oct 23 2004 14:07:24)

I tired a lot of things, to kill the stream and getting
disconnected...but nothing helped yet.

When i remember me right, we didnt have that prob @ 4.3.x. but not sure
tho.

I have no clue anymore :)


Previous Comments:
------------------------------------------------------------------------

[2004-10-23 17:40:51] [EMAIL PROTECTED]

fclose(STDIN); after successful fork() call should help you.

------------------------------------------------------------------------

[2004-10-23 15:01:21] toppi at kacke dot de

Description:
------------
After forking a process and setting the child as sessionleader (becomes
deamon) you cant disconnect from the current terminal-session (exit)
solong the child is in process.

After typing exit, the terminal prints the output from the child again.
Youre always connected but no more control

Current Config:

[EMAIL PROTECTED] simon]$ php -v
PHP 5.0.2 (cgi) (built: Oct 23 2004 14:07:24)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.2, Copyright (c) 1998-2004 Zend Technologies


Reproduce code:
---------------
#!/usr/local/bin/php -q
<?PHP

declare (ticks = 1);
set_time_limit (0);
ob_implicit_flush ();
error_reporting(E_ALL);

if( ($pid = pcntl_fork()) == -1 ) {
        echo "Error: Cant fork myself ! Dying.... \n";
}
elseif($pid) {
        //PARENT PROCESS
                echo "Parent-Pid: ".getmypid()." quits here\n";
                exit(0);
} else {
        //CHILD PROCESS
        // detatch from the controlling terminal
        if (!posix_setsid()) {
                die("could not detach from terminal");
        }
        //Install Signalhandler
        pcntl_signal(SIGTERM, "sig_handler");
        pcntl_signal(SIGCHLD, SIG_IGN);
        $i=0;
        $childpid = getmypid();

        //Do something for testing
        while ($i<20){
                sleep(1);
                echo "Child-Pid $childpid ist working -> type exit to quit your
shell-session ->it doesnt close the connex \n";
                $i++;
        }
        
        echo "Just now we get diconnectet from the shell\n";
        exit(0);
}

function sig_handler($signo) {
     switch($signo) {
         case SIGTERM:
             exit;
         case SIGCHLD:
             while( pcntl_waitpid(-1,$status,WNOHANG)>0 ) { }
             break;
         default:
             break;
     }
}

Expected result:
----------------
closing shell (telnet/ssh) and the child doing his background work

Actual result:
--------------
when starting ./testd.php (above) it looks

7360 simon     15   0  7308 2060 6856 S  0.0  0.2   0:00.00 sshd
7361 simon     25   0  4396 1340 3948 S  0.0  0.1   0:00.00 bash
7976 simon     16   0 10012 3452 8872 S  0.0  0.3   0:00.00 testd.php

when "EXIT" the shell
7360 simon     15   0  7308 2060 6856 S  0.0  0.2   0:00.00 sshd <---
left

solong the child repeats 20 times
7360 simon     15   0  7308 2060 6856 S  0.0  0.2   0:00.00 sshd

when the child is done
everthing got closed and the terminal is disconnected


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=30539&edit=1

Reply via email to