function forking_runtime($IOsock) { global $sock, $buffer, $chunks; socket_set_nonblock($IOsock); $last = time(); while ($sock) { buffer(); if ($last + 10 < time()) { return; } /*if($read = socket_read($IOsock,4096,PHP_NORMAL_READ) === false){ if(socket_last_error($IOsock) == 104){ return; } }*/ $action = trim($read); switch ($action) { case "buffer": $last = time(); $len = strlen($buffer) > 4096 ? 4096 : strlen($buffer); socket_write($IOsock, urlencode(substr($buffer, 0, $len)) . "\n"); $buffer = substr($buffer, $len); break; case "chunk": $last = time(); $packet = unserialize(urldecode(trim(socket_read($IOsock, 4096 * 16, PHP_NORMAL_READ)))); chunk_add($packet["chunk"], $packet["x"], $packet["z"]); chunk_clean($packet["x"], $packet["z"]); socket_write($IOsock, urlencode(serialize($chunks)) . "\n"); break; case "chunk2": $last = time(); $packet = unserialize(urldecode(trim(socket_read($IOsock, 4096 * 16, PHP_NORMAL_READ)))); chunk_edit_block($packet["x"], $packet["y"], $packet["z"], $packet["type"]); socket_write($IOsock, urlencode(serialize($chunks)) . "\n"); break; case "die": return; break; } } }
echo "<div class='row margin-right-thin margin-left-thin margin-top-thin'> <div class='col-xs-12'> <div class='alert alert-default'> $str_1[0] </div> </div> </div>\n"; } } echo "</body></html>\n"; /* * For performance reason, buffer the content * in a temporary archive file * once the chat file is too large */ if ($FileNbLine > MAX_LINE_IN_FILE) { buffer(implode('', $tmp), $tmpArchiveFile); // clean the original file $fp = fopen($fileChatName, "w"); fwrite($fp, implode('', $fileContent)); } function buffer($content, $tmpFile) { $fp = fopen($tmpFile, "a"); fwrite($fp, $content); }
if (!is_null(get_locale('charset'))) { header('Content-Type: text/html; charset=' . get_locale('charset')); } // page header with meta to refresh the page echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' . "\n" . '<html>' . "\n" . '<head>' . "\n" . '<title>' . get_lang('Chat') . '</title>' . '<meta http-equiv="refresh" content="' . $refresh_display_rate . ';url=./messageList.php?x=' . $x . '#final">' . "\n" . '<link rel="stylesheet" type="text/css" href="' . get_path('clarolineRepositoryWeb') . 'css/' . get_conf('claro_stylesheet') . '" >' . "\n" . '</head>' . "\n" . '<body>' . "\n" . "\n"; if (isset($cmdMsg)) { echo $cmdMsg; } echo implode("\n", $curDisplayLineList) . "\n" . '<p align="right"><small>' . $dateLastWrite . '</small></p>' . "\n\n" . '<a name="final"></a>' . "\n\n" . '</body>' . "\n\n" . '</html>' . "\n"; // FOR PERFORMANCE REASON, WE TRY TO KEEP THE ACTIVE CHAT FILE OF REASONNABLE // SIZE WHEN THE EXCESS LINES BECOME TOO HIGH WE REMOVE THEM FROM THE ACTIVE // CHAT FILE AND STORE THEM IN A SORT OF 'ON FLY BUFFER' WHILE WAITHING A // POSSIBLE EXPORT FOR DEFINITIVE STORAGE if ($activeLineCount > get_conf('max_line_in_file')) { // STORE THE EXCESS LINES INTO THE 'ON FLY BUFFER' buffer(implode('', $excessLineList), $onflySaveFile); // REFRESH THE ACTIVE CHAT FILE TO KEEP ONLY NON SAVED TAIL $fp = fopen($activeChatFile, 'w'); fwrite($fp, implode("\n", $curDisplayLineList)); } ////////////////////////////////////////////////////////////////////////////// /** * Store $content in a buffer * add an html header if it's new buffer * * @param string $content content to bufferise * @param string $tmpFile filename to store the content */ function buffer($content, $tmpFile) { if (!file_exists($tmpFile)) {