访问页面时,我的服务器 CPU 功率使用 11% / 100%,每个打开的选项卡都是另外 11%。这是我的 JScript 的代码:
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('pop');
ajaxDisplay.innerHTML = "Population: " + ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", "count.php", true);
ajaxRequest.send();
}
这是PHP代码:
<?php
$con = @mysql_connect("31.xx.x.xxx","xxxxxxxx","xxxxxxxxxxxx");
if (!$con)
{
echo('?');
}
@mysql_select_db("archstud_db", $con);
$result=mysql_query("SELECT * FROM chars");
$num=mysql_num_rows($result);
$num = $num;
echo $num;
@mysql_close($con);
?>
我还将 setInterval() 与我的 JScript 一起使用,window.onload 启动 setinterval 函数,每 6 秒刷新一次 JScript。
是什么占用了这么多CPU?另外,我该如何解决?