管理 HTML5 DIV 大小
Managing HTML5 DIV Size
所以前段时间我开发了一个Web应用程序,允许用户启动系统应用程序并在浏览器中查看该应用程序的调试日志。 每次将新行写入调试文件时,我都使用服务器端 EventSource 更新<div>
。 最终结果类似于浏览器中的"tail -f"。 一切都运行良好,直到有人开始以不同的方式使用该应用程序,其中> 10,000 行写入调试文件。
根据系统和浏览器的不同,任何超过 ~8-10k 行的内容都会导致浏览器挂起并响应非常缓慢。 不幸的是,我无法对写入调试文件的内容进行控制,但我认为我只能显示最后 2k 行。 但是,此页面在系统应用程序启动后立即打开,用户将停留在此页面上,直到系统应用程序调用完成..... 那么有没有办法清除以FIFO方式写入<div>
标签的内容? 否则,有没有办法提高处理更大数据量的性能? 以下是来自PHP的一些相关代码截图。
这是具有已更新<div>
的页面:
<script>
if(typeof(EventSource) !== "undefined") {
var source = new EventSource("stream.php<?php echo $built_url; ?>&inserted_procedure_id=<?php
echo $_GET['inserted_procedure_id'];
?>");
source.onmessage = function(event) {
document.getElementById("debug").innerHTML += event.data + "<br>";
var objDiv = document.getElementById('debug');
objDiv.scrollTop = objDiv.scrollHeight;
};
} else {
document.getElementById("debug").innerHTML = "Sorry, real time debug requires a modern browser with support for server side events. Please use current version of Firefox, Chrome or Safari for real-time debug... ";
}
</script>
这是来自流.php由前面的调用
if($_SESSION['done'] == 0 ){
clearstatcache();
$currentSize = filesize($file);
//echo "data: Test running, please wait ".$size."'n'n";
if ($size != $currentSize) {
$fh = fopen($file, "r");
fseek($fh, $size);
$dcounter=0;
sleep(5);
while ($d = fgets($fh)) {
//$d=str_replace(' ',' ',$d);
if (preg_match("/Executing test case:/", $d)) {
echo "data: <div style='position: fixed; bottom: 16px; width: 55px; height: 30px; z-index: 1002;'><form name='abort' id='abort' method='post' enctype='multipart/form-data' action='executor_state_change.php'><input type=hidden name=kill value=".$pid."/><font color=black><input type='button' value='Abort' onclick=openPopup();></font></form></div>'n'n";
}
echo "data: ".htmlspecialchars($d)."'n'n";
if (preg_match("/Please select continue when above instruction is complete/", $d)) {
$sql="SELECT wait FROM test_procedure_execution WHERE id=".$proc_id.";";
$sql_result=mysqli_query($con,"$sql");
$sql_row=mysqli_fetch_row($sql_result);
if($sql_row[0]==1){
echo "data: <form name='continue' id='continue' method='post' enctype='multipart/form-data' action='continue.php'><input type=hidden name=test_procedure_execution_id value=".$proc_id." /><font color=black><input type='submit' value='Continue' onclick='button.style.display =none;'></font></form>'n'n";
echo "data: <audio autoplay loop><source src='sounds/alert.wav' type='audio/wav'></audio>'n'n";
}
}
$dcounter++;
//ob_flush();
//flush();
}
fclose($fh);
$_SESSION["size"] = $currentSize;
}
将最后一个事件的消息 HTML 附加到 document.getElementById("debug").innerHTML
后,您应该进行处理。可能是这样的:
var content = document.getElementById("debug").innerHTML + event.data + "<br>";
var lines = content.split("<br>");
lines = lines.splice(lines.length - 2000, 2000);
document.getElementById("debug").innerHTML = lines.join("<br>");
相关文章:
- 限制一个DIV出现在另一个特定大小的DIV中
- 根据容器 DIV 中的图像动态调整容器 DIV 的大小
- Div 设置为视口高度,即使调整屏幕大小也是如此
- 检测第三方网站的动态DIV容器的大小
- 调整Div的大小,同时保持比例
- 单击按钮调整Div Width的大小
- imgAreaSelect JQuery插件可调整大小的Div's最小's宽度和高度
- 如何使用Jquery根据屏幕大小更改Div的大小
- 如何在浏览器中将 DIV 大小调整为全屏
- 调整窗口大小后仍然重定向Div
- Div 在使用此 JS 脚本时保持相同的大小
- Div 在调整大小/突出显示之前不会出现
- Div 动画会消失,而不是调整大小
- 根据 DIV 大小调整 iFrame 的大小
- 如何连续将 Div 大小调整为 100% VH
- HTML DIV 显示无元素调整大小
- 可在新行上调整大小的 DIV 制作文本框
- 管理 HTML5 DIV 大小
- 覆盖在“背景大小:包含”上的响应式 DIV - 解决警报触发的问题
- 宽度溢出时减小字体大小Div