我正在尝试创建一个简单的脚本,用于使用 jQuery 和 PHP 从 mysql 获取通知(我的代码如下)。目前 jquery 每秒获取 loadmore.php 并更新包含它的 div。我只是想知道如果网站流量很大,这是否会给服务器带来太大的压力?
源代码:index.php -
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#notifications').load('loadmore.php');
}, 1000); // refresh every 10000 milliseconds
</script>
<body>
<div id="notifications"> </div>
</body>
</html>
loadmore.php -
<?php
include('config.php');
?>
<?php
$sql=mysql_query("select * from updates ORDER BY item_id DESC LIMIT 9");
while($row=mysql_fetch_array($sql))
{
$msg_id=$row['item_id'];
$message=$row['item_content'];
?>
<?php echo $message; ?><br />
<?php } ?>