Ilan Kleiman
Ilan Kleiman

Reputation: 1209

How to keep Perl Script alive even after quitting the page?

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.

Upvotes: 0

Views: 230

Answers (1)

benjamin
benjamin

Reputation: 372

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!";

Upvotes: 1

Related Questions