当客户端浏览器关闭中断服务器端的Perl CGI脚本 [英] Interrupted server-side perl CGI script when client-side browser closes

查看:173
本文介绍了当客户端浏览器关闭中断服务器端的Perl CGI脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图解决现在有点问题相当长一段时间,但似乎我不能。

I've been trying to solve a little problem for quite a while now but it seems I'm not able to.

我写在提交表单它调用一个Perl CGI脚本的HTML页面。这CGI执行一定数量的任务,服务器端和我做剧本打印这些任务的步骤,到HTML页面上的iframe中。问题是,如果客户关闭浏览器或刚刚熄灭页面,在 CGI脚本被中断在服务器端。

I wrote an HTML page which calls a perl CGI script upon submitting a form. This CGI executes a certain number of tasks server-side and I made the script print the steps of these tasks into an iframe on the HTML page. The thing is, if the client closes his browser or just goes out of the page, the CGI script is interrupted on server-side.

HTML code:

HTML code:

<form action="/path/to/script.cgi" method="post" enctype="multipart/form-data" target="processing">
 <p>File to analyse: <input type="file" name="filename" size="50"/></p>
 <p><input type="submit" name="Submit" value="Analyse" /></p>
</form></font></p>

<p style="margin-left: 20"><font face="Arial" size="2" color="#000000">Analysing the file may take a while</font></p>
<iframe name="processing" width="70%" height="300">

</iframe>

CGI脚本:

my $query = new CGI;
print $query->header(-type => 'text/plain');
function1();
function2_takesLongTime($parameter);
function3();

因此​​,可以说是功能1只是preparing一些事情的文件分析(创建文件夹等)。
函数2是大功能(可能会持续15分钟)。这是一个Perl程序,它有很多它,因为文本/纯的CGI的头的,被重定向到HTML页面中的iframe打印(使用无缓冲$ |在程序中)。的httpd构造成使得超时是超过15分钟更长,因此它不会从那里来的。
function3是清理。

So lets say that "function1" is just preparing some things for the file analysis (creating folders etc.). "function2" is the big function (may last 15 minutes). It is a perl program and it has a lot of "prints" which, because of the "text/plain" header of the CGI, are redirected into the iframe of the html page (using no buffering $| in the program). httpd is configured so that the time-out is much longer than 15 minutes so it doesn't come from there. "function3" is clean-up.

如果客户端停留在html页面上,CGI脚本完美运行。
如果客户端被停止(例如,用户关闭窗口),功能1和2被执行的服务器端,但是脚本似乎之后被中断,由于没有清理是由

If the client stays on the html page, the CGI script runs perfectly. if the client is stopped (e.g. the user closes the window), function 1 and 2 are executed server-side, but the script seems to be interrupted after that because no clean-up is made.

我试图发动函数2作为一个独立的程序与系统命令,或者创建一个Perl库,并要求该库的主要功能,但最终还是以同样的方式。
我想,不管客户端保持与否页面上,服务器端脚本仍然会贯穿所有的方式。难道是因为文/平原的CGI脚本不能被返回给客户端脚本被中断?

I tried launching "function2" as an independent program with a system command, or creating a perl library and calling main function of this library, it still ends up the same way. I thought that no matter if the client stays or not on the page, the server-side script would still run all the way through. Is it because of the "text/plain" header of the CGI script which can't be returned to the client that the script is interrupted?

如果有人可以帮助我这个,我会非常感激。

If anyone can help me out with this, I'd be very grateful.

推荐答案

您需要建筑师软件不同。使用某种形式的异步编程中,作业队列将做精,只能使用CGI程序放在一个队列中的作业。通过使用你已经提到的库使过渡。

You need to architect your software differently. Use some sort of asynchronous programming, a job queue would do fine, and use the CGI program only to put a job in the queue. Make the transition by using the library you have already mentioned.

您似乎不熟悉的概念,所以我推荐一个非常简单的: Qudo 。如果你发现它过于严格,切换到 Gearman的,我认为这是最流行的一种Perl的世界(参见接口 的Gearman :: XS 的Gearman )。

You don't seem to be familiar with the concept, so I recommend a very simple one: Qudo. In case you find it too restrictive, switch to Gearman, which I think is the most popular one in the Perl world (see interfaces Gearman::XS and Gearman).

TIMTOWTDI:如果你能对CGI.pm共提供了执行环境放弃,例如见催化剂的 RunAfterRequest

TIMTOWTDI: If you can give up on the execution environment provided by CGI.pm altogether, see e.g. Catalyst's RunAfterRequest.

这篇关于当客户端浏览器关闭中断服务器端的Perl CGI脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆