后900秒混淆PHP / AJAX的超时时间(15分钟) [英] Confusing PHP/AJAX timeout after 900 secs(15 mins)
问题描述
所有的下方是基于Linux,最近的一个Apache,Apache的近期PHP模块。
all of the below is based on Linux, recent Apache, recent PHP module for Apache.
我遇到了我的AJAX + PHP的基于Web的应用程序的意外行为。 这是一个相当简单的AJAX方法,基本上涉及到一个请求到PHP脚本(execute.php)运行一段时间(几秒钟到几分钟)。作为一个测试设置中,PHP脚本(execute.php)基本上只是睡了一定的时间。当用量为899秒,它的工作原理,但是当我将它设置为900时,PHP脚本的答案(简单的echo())似乎过期或像这样(究竟是什么原因或理由实际上是未知我)作为请求不采取它的通知,因此不响应和相应的innerHTML不更新,符合市场预期。 请从下面的code。
I am experiencing an unexpected behavior for my AJAX+PHP based web-application. It is quite a simple AJAX approach, basically involving a request to a PHP-script (execute.php) that runs for some time (few seconds to several minutes). As a test-setup, the PHP-script (execute.php) basically just sleeps for a certain amount of time. When this amount is 899 seconds, it works, but when I set it to 900, the answer of the PHP-script (simple echo() ) seems to expire or something like this (what is exactly the cause or reason is actually unknown to me) as the request is not taking notice of it and thus not responding and the respective innerHTML is not updated, as expected. Please find the code below.
我现在想知道900秒此超时来自更重要的是,我怎么能prevent这种情况发生?毕竟,我认为这是,至少,AJAX的一个总体思路,以处理异步调用,一旦请求已更改其状态通知客户?!
I am now wondering where this "timeout" of 900 seconds comes from and even more important, how can I prevent that from happening? After all, I thought that this was, at least, one general idea of AJAX to handle asynchronous calls and notify the client as soon as a request has changed its state?!
process.php
process.php
<?php
session_start();
include("functions.php");
include("env.php");
html_head("Processing...");
$sid = $_SESSION['my_sid'];
?>
<script type="text/javascript">
function run_analyses(params){
<?php
print "var sid = \"". $sid ."\";
";
?>
// Use AJAX to execute the programs independenantly in the background
// Allows for the user to close the process-page and come back at a later point to the results-link, w/o need to wait.
if (window.XMLHttpRequest)
{
http_request = new XMLHttpRequest();
}
else
{
//Fallback for IE5 and IE6, as these don't support the above writing/code
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
//Is http_request still false
if (!http_request)
{
alert('Ende :( Kann keine XMLHTTP-Instanz erzeugen');
}
http_request.onreadystatechange=function(){
if (http_request.readyState==4 && http_request.status==200){
// Maybe used to display the progress of the execution
document.getElementById("output").innerHTML=http_request.responseText;
}
};
http_request.open("POST","execute.php",true);
//Send the proper header information along with the request
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", params.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(params);
};
</script>
<?php
$params "some_params";
print "
Starting AJAX-call<br>
<div style=\"width:400px; border: 1px black solid;\" id=\"output\">Use this to display an information about the progress</div>
<script type=\"text/javascript\">
run_analyses('".$params."');
</script>
<form action=\"./usersets/". $sid ."/results.html\" id=\"go_to_results\" method=\"POST\">
<input type='hidden' name=\"session_id\" value=\"" .$sid. "\">
</form>
";
html_foot();
?>
和execute.php:
and execute.php:
<?php
session_start();
include("functions.php");
include("env.php");
$sid = $_SESSION['my_sid'];
// Used to get the time at start of processing
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$start = $time;
session_write_close();
sleep(900); //899 here works
session_start();
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$finish = $time;
$total_time = round(($finish - $start), 3);
//echo 'Page generated in '.$total_time.' seconds.'."\n";
// Make it accessible for the results
$_SESSION['process_time'] = $total_time;
echo("none");
?>
所以,启动AJAX调用更新为无时,PHP脚本休眠899秒,但保持使用此显示有关进展情况的信息,如果值为900秒后的文字。
So the text after "Starting AJAX call" is updated to "none" when the PHP-script sleeps for 899 seconds, but stays "Use this to display an information about the progress" if that value is 900 seconds.
我真的非常期待您的建议。
I am really looking forward to your suggestions.
最好的,
阴影
修改
做的grep max_execution $(找到php.ini中)
给出:
/etc/php5/apache2/php.ini:max_execution_time = 30
/usr/share/doc/php5-common/examples/php.ini-development:max_execution_time = 30
/usr/share/doc/php5-common/examples/php.ini-production:max_execution_time = 30
/usr/share/php5/php.ini-production:max_execution_time = 30
/usr/share/php5/php.ini-production-dist:max_execution_time = 30
/usr/share/php5/php.ini-production.cli:max_execution_time = 30
EDIT2 当本地调用脚本(在我的本地Linux机器Apache网络服务器运行),在浏览器中有趣的是它的行为如预期respectes要求的回报率。但它表现出上面意外的行为在不同的机器上运行的Web服务器上运行时。上任何线索?因为我没有任何......对不起。
EDIT2 When calling the scripts locally (apache webserver running on my local linux machine) in my browser interestingly it behaves as expected and respectes the return of the request. But it exhibits the above unexpected behavior when run on a webserver running on a different machine. Any clues on that? Because I don't have any... Sorry.
推荐答案
在你的php.ini有一个的max_execution_time
,默认是30秒,因此它似乎某处它已经被设置为900。所以,我会检查那里第一次。信息: http://www.php.net /manual/en/info.configuration.php#ini.max-execution-time
In your php.ini there is a max_execution_time
, the default is 30 seconds, so it seems somewhere it has been set to 900. So I would check there first. Info: http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time
至于解决它,你可以编辑php.ini来设置该值非常高(或者为0,无限制),或者您可能能够使用此功能: http://php.net/manual/en/function.set-time-limit.php 重新设置后说,300秒。
As for solving it, you can edit the php.ini to set that value really high (or 0 for unlimited), or alternatively you might be able to use this function: http://php.net/manual/en/function.set-time-limit.php to reset it after say 300 seconds.
希望这有助于!
编辑:增加值为0的max_execution_time李的建议
added Lee's suggestion of 0 value max_execution_time
编辑2:
刚刚找到一些有趣的事情在这里 HTTP:// WWW .php.net /手动/ EN / function.set时,limit.php#75557
Just found something interesting here http://www.php.net/manual/en/function.set-time-limit.php#75557
请注意,在Linux下,睡眠时间被忽略,但在Windows下,他会成为执行时间。
Please note that, under Linux, sleeping time is ignored, but under Windows, it counts as execution time.
所以,这可能是为什么它的允许时间超过30秒来执行,但仍在削减其关闭最后。
So, that could be why its allowed to execute for longer than 30 seconds, but still cutting it off eventually.
这篇关于后900秒混淆PHP / AJAX的超时时间(15分钟)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!