Solved

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

Posted on 2007-12-04
1
753 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
This article will show, step by step, how to integrate R code into a R Sweave document
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

626 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