[英]Ajax request max execution timing out
While using this code to gather data using an Ajax XHTMLRequest I'm getting an PHP Max execution timeout 在使用此代码通过Ajax XHTMLRequest收集数据时,我得到了PHP Max执行超时
if(isset($_GET['func']) and $_GET['func'] == 'feed') {
global $ado;
$old_msg_id = $_GET['old_msg_id'];
$result = $ado->exec("SELECT * FROM `earnings` ORDER BY `id` DESC LIMIT 1");
while($row = $ado->fetch_assoc($result)) {
$last_msg_id = $row['id'];
}
while($last_msg_id <= $old_msg_id) {
$result = $ado->exec("SELECT * FROM `earnings` ORDER BY `id` DESC LIMIT 1");
while($row = $ado->fetch_assoc($result)) {
$last_msg_id = $row['id'];
}
}
$response = array();
$response['msg'] = 'new';
$response['old_msg_id'] = $last_msg_id;
echo json_encode($response);
}
The error I'm receiving in the error_log is 我在error_log中收到的错误是
PHP Fatal error: Maximum execution time of 30 seconds exceeded in /ajax.php on line 165
Line 165 is the following : 165行如下:
while($last_msg_id <= $old_msg_id) {
I currently don't see a problem with the code, any hints as to what's wrong ? 我目前看不到代码有问题,关于什么地方有什么暗示?
In AJAX you can post the time out like below, 在AJAX中,您可以按照以下方式发布超时时间,
jQuery.ajax({
url: 'ajaxhandler.php',
success: function (result) {
returned_value=result;
},
timeout: 10000,
async: false
});
If you are getting PHP you can change it in the PHP.ini 如果您要获取PHP,则可以在PHP.ini中进行更改
max_execution_time = 30 //make it like 300
Else in your PHP code use set_time_limit 否则,在您的PHP代码中使用set_time_limit
When called, set_time_limit() restarts the timeout counter from zero.
调用时,set_time_limit()从零重新启动超时计数器。 In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.
换句话说,如果超时是默认的30秒,并且在脚本执行后的25秒内执行了诸如set_time_limit(20)之类的调用,则该脚本将在超时之前运行总计45秒。
Also make sure that those while loops are not never ending loops. 还要确保那些while循环永远不会结束循环。
看来您的两个while循环执行所需的时间太长,数据库中是否分配了数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.