php聊天导致浏览器在wamp 32位上测试时冻结
php chat causes browser to freeze when tested on wamp 32 bit
这似乎是浏览器(IE、Firefox、Opera、Chrome、Safari等)中反复出现的问题。
端口转发依赖于路由器(而且我最近交换了笔记本的硬盘)我进去禁用了它,但仍然有同样的问题。这是聊天页面的代码。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
#smileys{
display:none;
padding-top:3px;
}
button{
border-color:#000000;
border-width:1px;
}
#mn{
width:50px;
}
.ooo{
border:solid;
border-color:black;
border-width:1px;
}
#main{
position:absolute;
padding-bottom:2px;
height:inherit;
width:300px;
border:solid;
border-color:black;
border-width:2px;
}
#posts{
border-bottom:solid 1px;
height:401px;
overflow-y:scroll;
background-color:#e2e2e2;
}
</style>
<script type="text/javascript">
var scroller = function(){
posts = document.getElementById("posts");
posts.scrollTop = posts.scrollHeight;
}
var menu=3;
var checksum = function(){
if (menu == 3){
document.getElementById('smileys').style.display="block";
document.bob.smileyhider.innerHTML="−";
menu=1;
}
else{
document.getElementById('smileys').style.display="none";
document.bob.smileyhider.innerHTML="+";
menu=3;
}
}
//Chat ajax loader
function update(){
var xhr;
if (window.XMLHttpRequest){ xhr = new XMLHttpRequest(); }
else{ xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
xhr.onreadystatechange = function(){
if (xhr.readyState==4 && xhr.status == 200){
document.getElementById('posts').innerHTML = xhr.responseText;
}
}
setInterval(update, 200);
xhr.open("GET","chatlog<?php echo date("d");?>.txt",true);
xhr.send(null);
}
update();
</script>
<!--chatting codes-->
<?php
//Chat Functions
function codes(){
$n = (isset($_REQUEST["sig"]) ? $_REQUEST["sig"] : null);
$input = (isset($_REQUEST["input"]) ? $_REQUEST["input"] : null);
$d = date("h:i A");
$nm = "<font color='black' size='2' face='times new roman'><b>(". htmlcheck($n). ")</b></font><img/> » <font size='2'>". $d
. "</font><b>:</b></font> <font size='3' face='times new roman'>"/*. smiles($input)*/. $input. "</font><br/>";
if($input==""||$n==""){
$nm = " ";
}
$file = "chatlog". date('d'). ".txt";
$data = fopen($file, 'a+');
fwrite($data, $nm);
fclose($data);
}
function smiles($ext){
$smile = array(
'<' => '<',
'>' => '>',
'&' => '&'
);
return (strtr($ext, $smile));
}
function htmlcheck($ext){
$code = array(
'<' => '<',
'>' => '>',
'&' => '&'
);
return (strtr($ext, $code));
}
?>
</head>
<form method="post" action="chat.php" name="bob">
<body onload="scroller(); update()"><div id="main">
<span id="liner"></form></span></form>
<div id="posts">
<!--insert include()code-->
<?php
//deals with above scripting code
codes();
include("chatlog". date('d'). ".txt");?>
</div><div align="center" id="buttons">
<button type="submit" class="send">Shout!</button><button type="reset">Reset</button>
<button onclick="checksum()" type="button" name="smileyhider">+</button><br/>
<input type="text" disabled="true" id="mn" value="<?php echo (isset($_REQUEST["sig"]) ? $_REQUEST["sig"] : null);; ?>" name="sig" />
<input name="input" id="input" type="text" class="ooo" maxlength="100" /></div></span></form>
<div id="smileys" align="justify"><center>
<p>Hidden Menu</p>
</center>
<a href="login.php" style="cursor:pointer;"><font color="grey" size="2">Sign-out</font></a>
</div></div></body></html>
作为一种偏好,它是用XHTML编写的;任何帮助都会很好,因为当页面总是冻结时,我无法测试php和javascript。
还值得一提的是,文件系统php函数是有效的,因为聊天日志文件是用正确的日期创建和命名的。这里的主要问题是冰冻;自从我第一次使用wamp 64位时遇到这个问题以来,我尝试将其删除并重新安装32位,但问题仍然存在。Wamp似乎不是这里的候选人,浏览器也不是(因为它出现在所有浏览器中)。任何帮助都会很好。
问题出在您的javascript中。如果浏览器锁定,那是因为成功地发送了一些东西。在服务器中查找故障是被误导的。
在函数update
中,您正在调用
setInterval(update, 200);
setInterval
创建了一个循环定时器,因此您在每个定时器间隔(以指数速率)创建越来越多的此类定时器。。。很快就会有大量的定时器每200ms调用CCD_ 3。在一秒钟内,您将拥有32个活动计时器。10秒内,将有1125899906842624个活动定时器。。。或者更确切地说。。。繁荣
你确定你不是说:
setTimeout(update, 200);
setTimeout
只创建一次计时器。
相关文章:
- 如何使用JavaScript模拟x86无符号32位整数乘法
- Javascript中的无符号32位整数
- Javascript是否为具有未定义值的变量分配32位内存
- firefox扩展,在32位和/或64位firefox(版本25.0.1)上使用js-cypes
- JavaScript 中的 32 位有符号整数数学
- 在节点中生成随机 32 位数字
- 错误:GM_setValue不支持的类型.支持的类型包括:字符串、布尔值和 32 位整数
- 读取 JavaScript 中包含 32 位浮点数的二进制文件
- 在 Javascript 中将 32 位 WAV 转换为 16 位 WAV
- 如何使用 JavaScript 知道安装的 JVM 是 32 位还是 64 位
- 从 IEEE 754 单精度(32 位)浮点(字符串表示)创建字节
- 如何在GLSL/WebGL中将一个32位整数打包为4.8位整数
- 画布到32位压缩ARGB
- 将4个8位无符号整数打包为32位浮点值
- javascript中带有无符号32位整数的位移位/类型转换
- php聊天导致浏览器在wamp 32位上测试时冻结
- JavaScript中的按位测试
- 将32位整数的非类型数组转换为UInt8Array的最有效方法
- Node-webkit应用程序不工作在Windows 7 32位
- 为什么使用32位BufferView时typearray访问速度更快