一个网站我正在开发基于客户端输入的PDF格式,我已经决定一旦购买完成那就开始生成pdf。原因是pdf可能会达到50/60MB,我不希望客户必须等待完成。来自Ajax的php脚本在浏览器关闭后停止加载
我使用Opencart和结帐成功页面我有一个Ajax命令加载PHP脚本。
我的印象是用户可以在脚本启动后关闭页面,但由于某种原因,我发现如果我希望文件出现在我的服务器上,我必须等待5/10秒才能关闭页面。
作为测试的一部分,它有点难以调试,需要立即关闭浏览器。
这是我的Ajax ...
$(document).ready(function() {
$.ajax({
url: 'index.php?route=pdfengine/pdfengine/generate_final_pdf',
type: 'post',
dataType: 'json',
data: {
},
beforeSend: function() {},
complete: function() {},
success: function(json) {}
});
});
和我的PHP(目前进出口装上它巨大的图像来表示加载时间)
public function generate_final_pdf() {
include('convert-to-pdf/mpdf.php');
$mpdf=new mPDF();
$stylesheet = file_get_contents(DIR_APPLICATION.'view/theme/rascal/stylesheet/stylesheet.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML('<html><body><div class="pdf-test-style"><img src="http://example.com/top_quality_image.jpg" />test</div><pagebreak><img src="http://example.com/top_quality_image2.jpg" />test<pagebreak><img src="http://example.com/top_quality_image3.jpg" />test</body></html>',2);
$mpdf->Output(DIR_FINAL_PDFS.'order_idpdfid-'.$this->session->data['pdf_id'].'.pdf','F');
}
编辑:
只是增加更多信息,我已阅读这些文章,看到的回应试图,
所以在t他提交了AJAX的香港专业教育学院设立..
ini_set('ignore_user_abort',true);
,并在Ajax调用伊夫组功能...
ini_set('ignore_user_abort',true);
set_time_limit(0);
对于第一个我跑的phpinfo(),它没有确认对我而言,ignore_user_abort已启用,意思很明显,该部分不是问题。
一些光睡前阅读的主题:) http://stackoverflow.com/questions/4806637/continue-processing-after-closing-connection http://stackoverflow.com/questions/8548419/most-simple-way开始一个新的进程线程在PHP http://stackoverflow.com/questions/138374/close-a-connection-early – 2014-09-04 12:16:13
这篇文章可能也是有益的/信息:[PHP的执行停止用户离开页面后?](http://stackoverflow.com/questions/1280291/does-php-execution-stop-after-a-user-leaves-the-page) – Lix 2014-09-04 12:17:19
这取决于您的设置。 这个[主题] [1]可能会有所帮助。 [1]:http://stackoverflow.com/questions/1280291/does-php-execution-stop-after-a-user-leaves-the-page – 2014-09-04 12:34:35