javascript - HTML 服务器发送的事件导致谷歌浏览器崩溃

标签 javascript php html google-chrome

我一直致力于开发基于 LAMP 的社交网络应用程序。但访问它有时会将我带到 Google Chrome 的“Aw Snap! Something Went wrong”页面。但是,它在所有其他浏览器上运行良好。这是由于在后台同时运行两个 SSE(服务器发送的事件)。

此外,我尝试删除服务器发送的事件,这似乎解决了问题,因为当时我没有看到错误。此外,该网站变得更快了。但我需要它们作为我页面上的主要功能。可以做些什么来让它发挥作用?

相同的脚本是:

聊天.php

<script>
if(typeof(EventSource)!=="undefined")
{ 
  var source2=new EventSource("onlineStudents.php");
  source2.onmessage=function(event2)
  {
     var data=JSON.parse(event2.data);
     $("#chat_head_number").html(": "+data['total']);
     for(var i=1;i<30;i++)
     {
        $("#chat_states_number"+i).html(" ");
        x=$("#state"+i).text();
        for( var j=0;j<data['statesName'].length;j++)
        {
             if(data['statesName'][j]==x)
             {
                 $("#chat_states_number"+i).html(" : "+data['statesNumber'][j]);
              }
        }
     }
   }
 }
 </script>

在线学生.php

<?php session_start();
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
require_once 'myfunctions.php';
$query="Select * from online_students where email<>'$_SESSION[user]'";
$result=  queryMysql($query);
$data["total"]=mysql_num_rows($result);
$query="Select distinct state from online_students";
$result=queryMysql($query);
while($row=  mysql_fetch_array($result))
{
    $query2="select * from online_students where state='$row[state]' and email<>'$_SESSION[user]'";
    $result2=queryMysql($query2);
    $data["statesName"][]=$row['state'];
    $data["statesNumber"][]=mysql_num_rows($result2);
}
$query="Select distinct college from online_students";
$result=  queryMysql($query);
while($row=  mysql_fetch_array($result))
{
    $query2="Select * from online_students where college='$row[college]' and email<>'$_SESSION[user]'";
    $result2=queryMysql($query2);
    $data["collegesName"][]=$row['college'];
    $data["collegesNumber"][]=mysql_num_rows($result2);
}
echo "data:".json_encode($data)."\n\n";
ob_flush();
flush();
sleep(3);
?>

标题.php

<script type="text/javascript">
if(typeof(EventSource)!=="undefined")
{
  var source=new EventSource("checkMessages.php");
  source.onmessage=function(event)
  {
      $("#new_message").html("Inbox"+event.data);
  };
}
else
{
  $("#new_message").html("HTML5 not supported");
} 
</script>

检查消息.php

<?php
session_start();
require_once 'myfunctions.php';
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
$userid=studentidOf($_SESSION['user']);
$query="Select distinct msgby from messages where msgfor='$userid'";
$result=queryMysql($query);
$k=mysql_num_rows($result);

$query="Select postnumber from notifications where notifor=$userid and postnumber is NOT NULL";
$result=queryMysql($query);
$k+=mysql_num_rows($result);
$collegeid=collegeidOf($_SESSION['user']);
$query="Select collegeid_post from notifications where notifor=$userid and      collegeid_post=$collegeid and notiby<>$userid";
$result=queryMysql($query);
$k+=mysql_num_rows($result);
$query="Select collegeid_forum from notifications where notifor=$userid and collegeid_forum=$collegeid and notiby<>$userid";
 $result=queryMysql($query);
$k+=mysql_num_rows($result);
$query="Select threadid from notifications where notifor=$userid and threadid is NOT NULL";
$result=queryMysql($query);
$k+=mysql_num_rows($result);
if($k>0)
  echo "data:($k)\n\n";
ob_flush();
flush();
?>

最佳答案

我尝试从 onlineStudents.php 中删除 sleep(3)。这解决了问题。

关于javascript - HTML 服务器发送的事件导致谷歌浏览器崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19397278/

相关文章:

c# - 从 Gridview RowDeleting 事件调用 Javascript 函数

javascript - IF、OR 和 AND 以及不同的结果 JavaScript

javascript - 如何使用 HTML 元素阻止 THREE.js 光线转换?

php - 如何访问 preg_replace_callback 中的变量?

html - 媒体查询不针对小尺寸运行

javascript - 如何更新画笔上多线的标记?

php - Javascript 不允许我用 PHP 设置变量?

php - Zend 框架 2 : Service locator in view helper

java.lang.ClassNotFoundException : Applet using external jar

javascript - 使用javascript读写sqlite数据库