Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Problem with fork in CGI script (again)

by asdfgroup (Beadle)
on Apr 26, 2003 at 13:33 UTC ( #253358=perlquestion: print w/replies, xml ) Need Help??

asdfgroup has asked for the wisdom of the Perl Monks concerning the following question:

Hi, This is repost of Problem with for in CGI with more comments and explaining (it looks like on prev post problems was not so clear for understanding as I thought ;( ). So problem :
I wonna to start some long-running code from web-interface. This can be done 2 ways :
- spawn separate process with help of fork
- use at or cron
Fork looks like more lazy (and right!) way to do this thing.
Unofrtunately my process works fine in command line, but stoped mystically in Apache (after about 10 mins of work)
Code looks like :
redirect_to("Prev_page.html") if fork(); #child here close STDIN; close STDERR; close STDOUT; # we inherit this filehandles from Apache. If we don't close, Apache w +ill wait for child use POSIX 'setsid'; setsid; #Change PGID. So Apache can't kill child (and won't know about it) # Long-running code here
Similar running program on the same server works without any problem (about 20 mins of execution).
Apache works under SuEXEC. No ulimits setted (checked both in CGI script and in shell for this user).

Can anybody imagine reason why this can happens ?
Sincerely, Nikita Savin

Replies are listed 'Best First'.
Re: Problem with fork in CGI script (again)
by pzbagel (Chaplain) on Apr 26, 2003 at 16:17 UTC

    Modifying your timeout directive in your apache httpd.conf file may be the answer. It defaults to 300 seconds (5 minutes) if you change that to 1800 (30 minutes) that may allow enough time for your script to run.

    I believe others have also previously recommended that you output some sort of status messages which the script is running to avoid the timeout as well as let the user know you are actually doing something.

    Hope that helps.

Re: Problem with fork in CGI script (again)
by eduardo (Curate) on Apr 26, 2003 at 20:22 UTC

    Do you ever read merlyn's super splendid WebTechniques columns? I find that for 90% of the problems I have developing web based interfaces, there is a WebTechniques column that has already answered it.

    And check it out, this column looks like it might be right up your alley. I know that it worked for me when I had to implement a long running process that was kicked off from a webpage :) Enjoy, and bookmark.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://253358]
Approved by valdez
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2020-07-04 09:56 GMT
Find Nodes?
    Voting Booth?

    No recent polls found