Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

705 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

18 Experts available now in Live!

Get 1:1 Help Now