Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 导致服务器崩溃的Ajax请求_Php_Mysql_Ajax - Fatal编程技术网

Php 导致服务器崩溃的Ajax请求

Php 导致服务器崩溃的Ajax请求,php,mysql,ajax,Php,Mysql,Ajax,我有一个网站,学生可以在线参加测验。每次他们选择答案(单选按钮用于多选)时,执行以下代码: $('input:radio').click(function(){ var questionId = $(this).parent().parent().find('.qid').val(); var answer = $(this).val(); $.ajax({ type: "POST", url: "insertqanswerajax.php", d

我有一个网站,学生可以在线参加测验。每次他们选择答案(单选按钮用于多选)时,执行以下代码:

$('input:radio').click(function(){
var questionId = $(this).parent().parent().find('.qid').val();
var answer = $(this).val();
$.ajax({
        type: "POST",
        url: "insertqanswerajax.php",
        data: {questionId: questionId, answer: answer},
    });

});
insertqanswerajax.php代码:

<?php session_start();
include_once('../includes/connect.php');     //connect to database
include_once('../functions/quizfunctions.php');   //all functions
$userSubject = $_SESSION['subject'];
$userGradeLevel = $_SESSION['gradeLevel'];
$userId = $_SESSION['userId'];
$questionId = $_POST['questionId'];
$answer = $_POST['answer'];



insertQuizAnswer($questionId, $userId, $answer, 1);
$DB = null;

?>
代码工作正常,直到卷变大(几百个用户正在进行测试)。服务器崩溃,出现默认的500错误,站点在一两分钟后恢复。只需反复单击一个单选按钮,即可复制错误

我的内存限制是524兆字节,可能比我的计划实际允许的要高

这部分代码存在的原因是在用户访问时保存答案,这允许他们稍后返回,或者在学校网络断开(确实如此)的情况下重新选择中断的位置


我有一个共享托管计划,我知道这有它的局限性,我正在尝试确定是否有一种方法可以使这项工作,或者如果它只是不可能与我的共享计划

你的主机有问题。
要解决这个问题,您必须购买带宽更大的托管计划(以同时处理多个请求)。您可以与您的主机提供商讨论此问题。

我认为您应该首先检查错误日志或向您的主机管理员查询日志。我已经检查了错误日志,但没有任何结果。我的印象是,一旦服务器宕机,服务器甚至无法收到请求。这不是对你问题的回答,但我真的建议你考虑使用CouchDB、MongoDB等工具来存储这种短期数据。它们更加轻量级,能够更好地处理并发用户,占用的内存也少得多。
function insertQuizAnswer($questionId, $userId, $answer, $testId){
global $DB;                                          
$standardsHandle = $DB->prepare("INSERT INTO quizanswers (questionid, userid, answer, testid)
                                VALUES (:questionId, :userId, :answer, :testId)
                                ");   //get all benchmark grades for user
$standardsHandle->bindParam(':questionId', $questionId);
$standardsHandle->bindParam(':userId', $userId);
$standardsHandle->bindParam(':answer', $answer);
$standardsHandle->bindParam(':testId', $testId);
$standardsHandle->execute();
$standardsHandle = null;
}