Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
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…
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…

752 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