ID:               20023
 User updated by:  [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
-Status:           Feedback
+Status:           Open
 Bug Type:         Sockets related
 Operating System: Win 98 SP2
-PHP Version:      4.2.2
+PHP Version:      4.2.2 4.3
 New Comment:

I did as you suggested. But now it isn't working at all
anymore: as with 4.2.2 I can do everything up to (but not
including) entering a character into the telnet client.

doing socket_read or even an
echo(socket_strerror(socket_last_error($client[$i])));
upon recieving that character triggers a Page Fault in php4ts.


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

[2002-10-22 10:19:05] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip

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

[2002-10-22 05:27:22] [EMAIL PROTECTED]

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 this bug report at http://bugs.php.net/?id=20023&edit=1

Reply via email to