ID: 30539 Comment by: lobbin at localhost dot nu Reported By: toppi at kacke dot de Status: Open Bug Type: *General Issues Operating System: Fedora Core 2 Linux PHP Version: 5.0.2 New Comment:
I've seen this problem pretty often, it might be related to (open)ssh and your shell. More info here: http://www.openssh.com/faq.html#3.10 Previous Comments: ------------------------------------------------------------------------ [2004-10-24 13:50:41] toppi at kacke dot de I tired the code by using cli now. Same problem even when i close STDIN. Also i tired it, by creating a shutdown_function() register_shutdown_function( create_function('','fclose(STDIN); fclose(STDOUT); fclose(STDERR); return true;') ); A test on another system, to make sure its not a os-config thingo, gives the same result. Run the code as root (to make sure, its no perm. thing) doesnt help tho. The child always post his outputstream ahead tru sshd (but no bash alive). When creating a socket around the child and you just close the terminal-window to get disconnected from the master, the code chrashes on connect. ------------------------------------------------------------------------ [2004-10-24 06:53:45] [EMAIL PROTECTED] Use CLI then? Personally I do not think that CGI version is the best choice for daemons, as it wasn't designed for such purposes. ------------------------------------------------------------------------ [2004-10-23 20:28:39] toppi at kacke dot de 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 :) ------------------------------------------------------------------------ [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
