php聊天导致浏览器在wamp 32位上测试时冻结

php chat causes browser to freeze when tested on wamp 32 bit

本文关键字:32位 测试 冻结 wamp 聊天 浏览器 php      更新时间:2023-09-26

这似乎是浏览器(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="&minus;";
 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/> &raquo; <font size='2'>". $d
. "</font><b>:</b></font>&emsp;<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(        
    '<' => '&lt;',
    '>' => '&gt;',
    '&' => '&amp;'
    );
return (strtr($ext, $smile));
}
function htmlcheck($ext){
$code = array(        
    '<' => '&lt;',
    '>' => '&gt;',
    '&' => '&amp;'
    );
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只创建一次计时器。