php项目过段时间就崩溃,为什么我的PHP会话不断结束,Apache偶尔会崩溃?

//Function that gets the chat from backend

function showmessage(str) {

if (str == "") {

return;

} else {

if (window.XMLHttpRequest) {

xmlhttp = new XMLHttpRequest();

} else {

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

xmlhttp.onreadystatechange = function() {

if (this.readyState == 4 && this.status == 200) {

document.getElementById("chat").innerHTML = this.responseText;

}

};

xmlhttp.open("GET","/backend-display.php?q="+str,true);

xmlhttp.send();

}

}

//Show any messages that will pop-up

setInterval('showmessage()',400);

//Function that updates new rows

function newrows(str) {

if (str == "") {

return;

} else {

if (window.XMLHttpRequest) {

xmlhttp = new XMLHttpRequest();

} else {

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

xmlhttp.onreadystatechange = function() {

if (this.readyState == 4 && this.status == 200) {

document.getElementById("test").innerHTML = this.responseText;

var elem = document.getElementById('chat');

elem.scrollTop = elem.scrollHeight;

}

};

xmlhttp.open("GET","/test2.php?success=true"+str,true);

xmlhttp.send();

}

}

//Updates new rows every x seconds

setInterval('newrows()',300);

//Backend to send a message

function loadDoc() {

var xhttp = new XMLHttpRequest();

var mes = document.getElementById("message").value;

var message = "message=" +mes;

xhttp.onreadystatechange = function() {

if (this.readyState == 4 && this.status == 200) {

document.getElementById("input").innerHTML = this.responseText;

}

};

xhttp.open("POST", "/backend-input.php", true);

xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xhttp.send(message);

document.forms["form"].reset();

}

的php.ini配置:

后端输入:

$name = $_SESSION["name"];

$messageunfilter = $_POST["message"];

$con = mysqli_connect('localhost','root','','chat');

if (!$con) {

die('Could not connect: ' . mysqli_error($con));

}

if(empty($_POST["message"])){

echo "You must enter a message...";

exit();

}else{

echo "success";

}

//Checking SQL

$check = array("\\", "'");

$change = array("\\\\", "''");

$messagefilter = str_replace($check, $change, $messageunfilter);

date_default_timezone_set('Europe/London');

$current_date = date("Y-m-d H:i:s");

mysqli_select_db($con,"ajax_demo");

$sql="INSERT INTO `chat` (`id`, `username`, `message`, `date`) VALUES (NULL, '$name', '$messagefilter', '$current_date')";

$result = mysqli_query($con,$sql);

mysqli_close($con);

?>

后端从DB recieving消息:

session_start();

?>

$name = $_SESSION["name"];

$con = mysqli_connect('localhost','root','','chat');

if (!$con) {

die('Could not connect: ' . mysqli_error($con));

}

mysqli_select_db($con,"ajax_demo");

$sql="SELECT * FROM `chat` ORDER BY date";

$result = mysqli_query($con,$sql);

$numrows = mysqli_num_rows($result);

if($numrows == "0" or !isset($_SESSION["name"])){

echo "

";

echo "

System
";

echo "

There are no messages to display...
";

echo "

";

exit();

}else{

echo "";

}

echo "

";

while($row = mysqli_fetch_array($result)) {

$class_msg = "msg";

$class_username = "username";

$class_message = "message";

if ($row['username'] == $_SESSION['name']) {

$class_msg = "msg_user";

$class_username = "username_user";

$class_message = "message_user";

}

echo "

";

echo "

" . $row['username'] . "
";

echo "

" . $row['message'] . "
";

echo "

";

}

echo "

";

mysqli_close($con);

?>

我知道websockets和我的代码需要清理很多,以及我的陈述没有准备的事实。

由于某些原因,系统运行5分钟左右后,会话似乎被破坏?

我不知道这是为什么?是因为我多次请求吗?

即使我只有2个用户连接消息对方,它仍然崩溃,它可以在60秒,1分钟后崩溃?

有人可以帮我找出为什么这是,我会更感激。

非常感谢你看这篇文章,即使这意味着很多! (对不起,我的代码超载在这里,我只是想确保我显示你的一切,我可以!)

2017-09-03

Galliger

+0

查看apache日志查看可能的错误信息 –

+0

@MiSAKACHi主要问题是我的会话不断被破坏,我认为apache崩溃与其他事情有关,因为它只有一次崩溃! –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值