Solved

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

Posted on 2007-12-04
1
738 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now