Hi,
I'm kinda new at PHP and trying out 4.2.2.on Windows 98 using
Apache 1.3.23 as webserver. however my Problem arises also with calling
PHP -f in the box:
Basically I do (leaving out error checking here):
<?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
}
}
}
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 my PHP -f ...
dies with a page fault when getting to "socket_read".
I tried to have a look at "socket_last_error" before reading
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...
Any hints on how I get around this?
Thanks in advance
Sven Schnitzke
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php