\n"; } else { $s = array($server); $t = $timeout == -1 ? NULL : $timeout; while ($r = $s and stream_select($r, $n=NULL, $n=NULL, $t)) { foreach ($r as $stream) { if ($stream == $server) { // new client $s[] = stream_socket_accept($server, -1); } else { if (!fputs($file, fgets($stream))) { fclose($stream); array_splice($s, array_search($stream, $s), 1); } } } } } }