So I have a Perl script being hosted. My script needs to be able to run even after the client closes the page. So let's say I'm visiting the page at http://example.com/keptalive.pl. As soon as if visit the page it sends the request to the server. Now the server takes over 3+ minutes to process this request... I would like the client to be able to close the browser window, and still have the server process the request rather then let it die.
Asked
Active
Viewed 211 times
0
-
Why have you asked the [same question](http://stackoverflow.com/questions/20040230/how-to-keep-alive-perl-script) twice? Please add more of this information in that other SO post instead of opening a new question. – S.R.I Nov 18 '13 at 05:10
-
@S.R.I it's not the same question. One is based off of keeping the connection alive with the client connected. With this question I'm asking how to keep it alive after the client quits. – Ilan Kleiman Nov 18 '13 at 05:12
-
Well, to me it looks like both of these questions could be handled by that other post. However, in the interest of caution and security, if you're doing what I think you're trying to do - you're opening yourself to a potential security problem. Browsers and web-based scripts quit on closing client connection for a reason. In any case, please ask this question on the linked SO question. – S.R.I Nov 18 '13 at 05:17
-
@S.R.I They are two separate problems/questions. I don't see the point in joining the two questions in one. (With the other question already handled). They most likely have completely separate solutions, with different points of action. – Ilan Kleiman Nov 18 '13 at 05:23
-
What exactly is your goal? If you want to run an asynchronous process, then do it right. Have a background process receive requests from the CGI perl script and decouple the processing from handling the request. – Jim Garrison Nov 18 '13 at 05:23
1 Answers
1
Seems like this answers your question.
From the answer, use batch
on linux:
import os
os.system("batch <<< '/home/some_user/do_the_due.py'")
# or if you don't want to wait for system idle,
# os.system("at now <<< '/home/some_user/do_the_due.py'")
print 'Content-type: text/html\n'
print 'Done!'
There is of course, no reason why you couldn't do this in perl, using system
, as well.
system("batch <<< 'home/some_user/dosomething.pl'");
# then print your page
print "Content-type: text/html\n";
print "Done!";