From:             [EMAIL PROTECTED]
Operating system: Win 98 SP2
PHP version:      4.2.2
PHP Bug Type:     Reproducible crash
Bug description:  Page Fault on Socket read

I use this with PHP 4.2.2 Win executable version:

<?php
// set up listener and wait for clients
$listener = socket_create(AF_INET, SOCK_STREAM, 0);
socket_setopt($listener, SOL_SOCKET, SO_REUSEADDR, 1);
socket_bind($listener, "0.0.0.0", 1234);
if (socket_listen($listener, 5);
$client = array();

// monitoring loop
while (true)
{
    $read[0] = $listener;
    // keep track of clients
    for ($i = 0; $i < MAX_CLIENTS; i++)
    {
        if ($client[$i] != null)
             $read[$i + 1] = $client[$i];
    }
    
    // watch for any socket activity
    $nready = socket_select($read, $null, $null, null);
    
    if (in_array($listener, $read))
    {
        // here we have a new client
        for ($i = 0; $i < MAX_CLIENTS; $i++)
        {
            if ($client[$i] == null)
            {    
                $client[$i] = socket_accept($listener);
                break;
            }
        }
        if (--$nready <= 0)
            continue;
    }

    // get data from socket(s) marked as active
    for ($i = 0; $i < MAX_CLIENTS; $i++)
    {
        if (in_array($client[$i], $read))
        {
            socket_getpeername($client[$i], $host, $port);
            $n = socket_read($client[$i], 16300);
            if (strlen($n) > 0)
                echo "rcv from $host:$port:$n\r\n";
            // else close and cleanup socket
        }
    }
}

This is, slightly modified, the example from the manual.

Everything works fine as long as I have well-behaved clients.
But if I for example try this against a telnet client and just close 
it without properly disconnecting before my script (by the way 
running in a dos box with php -f ... ) in turn 
dies with a page fault when getting to "socket_read".

I tried to have a look at "socket_last_error" after "socket_select" 
but that does not help since it says: 0. "socket_select" lets 
loose upon the killing of the client, putting the socket into 
the "$read" array. So I have to look at it...

-- 
Edit bug report at http://bugs.php.net/?id=20023&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=20023&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=20023&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=20023&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=20023&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=20023&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=20023&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=20023&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=20023&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=20023&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=20023&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20023&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=20023&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=20023&r=isapi

Reply via email to