- $body = "";
-
-
- $header_out = array();
- $body = "";
- index_rd_ifra_main($room, $room->user[$s2u[intval($sock)]], $body);
- echo "SPIA: [$body]\n";
- fwrite($sock, headers_render($header_out).$body);
- fflush($sock);
+ $user = $room->user[$s2u[intval($sock)]];
+ $response = $user->rd_cache_get();
+ if ($response == "") {
+ $content = "";
+ index_rd_ifra_main($room, $user, $content);
+
+ if ($content == "" && $user->rd_kalive_is_expired($curtime)) {
+ $content = index_rd_ifra_keepalive($user);
+ }
+ if ($content != "") {
+ $response = chunked_content($content);
+ }
+ }
+
+ if ($response != "") {
+ echo "SPIA: [".substr($response, 0, 60)."...]\n";
+ $response_l = mb_strlen($response, "ASCII");
+ $wret = @fwrite($sock, $response);
+ if ($wret < $response_l) {
+ printf("TROUBLE WITH FWRITE: %d\n", $wret);
+ $user->rd_cache_set(mb_substr($response, $wret, $response_l - $wret, "ASCII"));
+ }
+ else {
+ $user->rd_cache_set("");
+ }
+ fflush($sock);
+ $user->rd_kalive_reset($curtime);
+ }
+
+ // close socket after a while to prevent client memory consumption
+ if ($user->rd_endtime_is_expired($curtime)) {
+ // $user_a[$s2u[intval($sock)]]->disable();
+ if ($room->user[$s2u[intval($sock)]]->rd_socket_get() != NULL) {
+ $room->user[$s2u[intval($sock)]]->rd_socket_set(NULL);
+ }
+ unset($socks[intval($sock)]);
+ unset($s2u[intval($sock)]);
+ fclose($sock);
+ printf("CLOSE ON LOOP\n");
+ }