所以你好社区。 p>
我开发了一个通过PHP生成大型文件的网站,最多可能需要5分钟。我提出了PHP值的设置以获得最大执行时间,这里没问题。
当用户调用生成的文件时,当前页面上会显示一个加载器,这个加载器执行一个循环的Ajax请求,读取一个包含文件生成状态的简单文本文件。
例如:«生成线120/350»。
这很好用,每次te ajax请求提供结果时,它会在2.5秒后再次调用自己。直到大约1分30秒,然后日志冻结。我无法弄清楚会发生什么。这是我到目前为止所得到的:
谁能告诉您发生了什么/如何解决这个问题?
Jquery插件(手工制作):
;jQuery(function ($) {
// dynlog object
$.fn.dynlog = function(options){
// user id MUST be defined
if(typeof(uid) == "undefined"){
console.log("Function dynlog: Missing current user ID!");
return;
}
uid = parseInt( uid );
// "$D" is current instance of the object
var $D = this;
// plugin's default options
var defaults = {
// frequency in milliseconds between two ajax checks of the log value
// raise for optimisation, lower for user experience
frequency: 1500
, default_text: 'Chargement'
// Callbacks
, onStart: function() { return true; }
, onStop: function(inst) { return true; }
, onInit: function(inst) { return true; }
}
// mergin defaults, and given params
$D.settings = $.extend({}, defaults, options);
// LOCAL VARS
var running = false
, runningClass = false
, return_txt
, current_txt
, client = new XMLHttpRequest() // For reading file
, to // Timeout, with throttle
;
// /////////////////////
// METHODS:
// /////////////////
// init
$D.init = function(inst) {
// external function
$D.settings.onInit();
}
// /////////////////
// Démarrer l'affichage du log
$D.start = function(){
running = true;
// Adding class 'running' to container
$D.find('.dynlog-container').addClass('running');
// Let's go get the log value
$D.fetch();
}
// /////////////////
// Go seek log value
$D.fetch = function(){
// read log text file => see further fo "on-read" event
client.open('GET', 'files/dynlog/'+uid+'.txt');
client.send(null);
}
// /////////////////
// Arréter l'affichage du log
$D.stop = function(){
// do not update anymore, please
running = false;
// removes running status fos visual update
$D.find('.dynlog-container').removeClass('running');
runningClass = false;
}
// /////////////////////
// PRIVATE METHODS
// /////////////////////
// /////////////////
// Update log visually
var update = function(text){
// Afficher le texte donné
$D.find('.dynlog-container .dynlog-message').text( text );
};
// /////////////////////
// ONCE FILE IS SEEKED
// /////////////////////
// /////////////////
// What happens when file seeked ?
client.onreadystatechange = function(){
// Text to display in log
return_txt = false;
// If file is found
if(client.status == 200){
// its content is the text to display
return_txt = client.responseText;
}
// If file NOT found or text is defined but null
if(client.status == 404 || return_txt === ''){
// please write the default value
return_txt = $D.settings.default_text;
}
// if text is retuned AND different from previous
if(return_txt != '' && return_txt != current_txt){
// then please update it
current_txt = return_txt;
update( current_txt );
}
// cycle the call if we are still running
if(client.status != 0 && running){
// throttler :
clearTimeout(to);
// re-call the start stuff
to = setTimeout(function(){
// $D.start();
$D.fetch();
}, $D.settings.frequency);
}
};
// /////////////////////
// Applying plugin to jquery object
$(this).each(function(){
// création du template
var tpl = '<div class="dynlog-container">'
+'<div class="dynlog-message"></div>'
+'</div>'
;
$(this).append(tpl);
});
// /////////////////////
// call the "constructor" method
$D.init(this);
// /////////////////////
// returns this instance
return this;
}
});
PHP脚本基本上可以:
file_put_contents( $file, $contents);