Solved

Want my perl CGI program to continue without waiting for return from a subroutine

Posted on 2007-12-04
1
748 Views
Last Modified: 2013-12-25
Hi,
I'm writing perl CGI programs that will run a Web site.  On one page, if the user clicks on a link, he initiates some processing, and he'll be taken to another page.  The processing will read data from a couple other Web sites, process the data, and send email to the user.  But there's no reason the user should have to wait for all that to happen before being sent to the next page for him to view.  The processing could happen in the background, so to speak.

I'd like to find a way for the program that initiates the processing to continue, sending the user to his new page, without waiting for the processing to finish.  Is there a way to do that?
Thanks,
--Steve

0
Comment
Question by:StevenMiles
1 Comment
 
LVL 39

Accepted Solution

by:
Adam314 earned 250 total points
ID: 20404206
You should fork the main process.
http://perldoc.perl.org/functions/fork.html
This will split the main process into to: a parent and a child.
You should have the parent continue with whatever it should do.
Have the child call the subroutine that does the background processing.

eg:
my $pid=fork;
die "Could not fork: $!\n" unless defined $pid;
if(!$pid) {
    #This is the child
    your_subroutine();
    exit;
}
#Parent continues here
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question