ID:               20745
 Comment by:       steven dot gilberd at gmail dot com
 Reported By:      polone at townnews dot com
 Status:           No Feedback
 Bug Type:         Sockets related
 Operating System: Linux
 PHP Version:      4.2.3
 New Comment:

This bug still appears to exist (PHP 5.2.3-1+b1 (cli)), on at least
socket_accept().

The signals just queue up until the socket receives a connection and
unblocks, at which point the signals are processed as normal.

I would like to request that this bug be reactivated; leaving it
sitting here as 'No Feedback' isn't helping anyone.


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

[2007-03-12 18:54:30] antoine dot bajolet at tdf dot fr

Hello,

The issue still exists,

PHP Version => 4.4.6
System => Linux pentium2.antoine 2.6.20 #5 Sun Feb 18 16:28:17 CET 2007
i686
Build Date => Mar  6 2007 21:15:38

Complete code to reproduce error :

script.php
------------------------------------------------------------------

#!/usr/local/bin/php
<?php
define ( 'BIND_PORT', 3333 );
/* Signal Handler */
function signalHandler( $sig ) {
    switch ( $sig ) {
        case SIGTERM :
            exit( 0 );
            break;

        case SIGCHLD :
            pcntl_waitpid(-1,$status,WNOHANG);
            break;
    }
}
print "My PID is ".posix_getpid()."\n";
declare ( ticks = 1 );
pcntl_signal( SIGTERM, 'signalHandler' );
pcntl_signal( SIGCHLD, 'signalHandler' );

// infinite execution time
set_time_limit( 0 );
// Socket creation
$sock = socket_create ( AF_INET, SOCK_STREAM, SOL_TCP );
// Bind sur le port BIND_PORT
if ( !socket_bind( $sock, '0.0.0.0', BIND_PORT ) ) {
    print "Unable to bind to port " . BIND_PORT . " !\n";
    exit( 1 );
}
// Listening up to 16 buffets
socket_listen ( $sock, 16 );
// Infinite loop
while ( true ) {
    // Wait for incoming connections, hangs signal handling
    $subsock = socket_accept ( $sock );
    // Connection received, forking sub-process
    $subPid = pcntl_fork();

    if ( $subPid === 0 ) {
        // Get remote informations
        socket_getpeername( $subsock , $remoteAddr , $remotePort );
        socket_write( $subsock, 'Simple Socket Server accepting
commands from ' . $remoteAddr . "\n" );
        // Whe are in interactive mode
        while ( true ) {
            $received = socket_read ( $subsock, 65536, PHP_NORMAL_READ
);
            // Clean shutdown
            if ( !$received ) {
                socket_shutdown( $subsock, 2 );
                socket_close( $subsock );
                exit( 0 );
            }
            // Cleaning entry
            $received = trim( $received );
            if ( $received ) {
                // two commands : HELLO and QUIT
                switch ( $received ) {
                    case 'HELLO':
                        socket_write( $subsock, 'HELLO ' . $remoteAddr
. "\n" );
                        break;
                    case 'QUIT':
                        // (shutdown)
                        socket_write( $subsock, 'BYE' . "\n" );
                        socket_shutdown( $subsock, 2 );
                        socket_close( $subsock );
                        exit( 0 );
                        break;
                    default :
                        socket_write( $subsock, 'Unknown command...' .
"\n" );
                }
            }
        }
    }
} // while
?>

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

Commands :
[Shell1]$ ./script.php
My PID is 18135

[Shell2]$ kill 18135
<Happens nothing on Shell1...>

[Shell2]$  telnet localhost 3333
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host

[Shell1] : The script exits.

=> The signal is properly intercepted but the handler is only called
when the script continues after socket_accept().

Whe are using a little more complex code when the fist process is a
child of a fork itself : At this time, the only way to end it is a not
very clean SIGKILL.

Regards,
AB

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

[2006-05-25 19:31:39] lindsay at bitleap dot com

I still see this issue with php 5.1.4.  I did notice that the signal
will queue up and on the next inbound connection the queued signal
executes.

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

[2006-02-09 18:55:35] flachi at gmail dot com

I also have this problem with PHP 4.4.2. Is there any way to fix it ?

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

[2003-01-02 02:50:09] piotr at t-p-l dot com

I'd like to revive this bug .. as of 4.3.0 this beheaviour persists ..
I even tried this define(ticks=1); approach quoted in one of the related
bugs .. it didnt help .. during a call to socket_accept() as far as I
can see (I've tested only with SIGTERM and SIGINT) .. those handlers
never get called .. with the new feature (the 3rd param on
pcntl_signal() .. set to false) .. the socket_accept() call gets
interrupted, but the handler is still not called. I would say there is a
need to resolve this .. right now there is no way to cleanly kill a
daemon process running php unless non blocking sockets are used .. which
is basicaly a waste of cpu cycles .. 

Please respond as to the status of this problem asap.

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

[2002-12-15 04:05:02] [EMAIL PROTECTED]

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.



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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/20745

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

Reply via email to