Long running CGI script

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have a script that asks for some input on several screens, and at the
end it kicks off a connection to a database which does some work that
could potentially take a long time.  I dont want to hold up displaying
the webpage while this is running - I would prefer to print a message
to the browser saying the job is running in the background.  In other
works, I want to allow the script to continue running, but notify the
browser that I have finished talking to it.

I found a script written by Randal Schwartz that says todo this all you
have todo is close STDIN and STDOUT:-

open STDIN, "</dev/null";
open STDOUT, ">/dev/null";

However when I do this the script seem to die (although no die message
gets into the error logs - it just seems to give up silently).  Also, a
system command to copy a file gives an error "Not A Typewriter".  If I
remove the system command, the database connection does not work
correctly (it seems to work sometimes though??!!).

How can I 'disconnnect' the browser let my script continue todo some
work?  I would prefer not to fork.



Re: Long running CGI script

I always thought you had to "fork" to do that.  In addition you need to
close STDOUT (as you've done) before you fork.

As for the dying, you need to find out where it's hapenning.  You
mention that you have a log file.  Make sure you do $| = 1 after
opening the log file, and just print progress messages to the log file
every few lines in your code.  Eventually you'll find the exact place
where it's dying, and you'll be able to debug it better.

Re: Long running CGI script

Quoted text here. Click to load it

And here is one from Randal that does fork:


Quoted text here. Click to load it

Can you explain why you do not want to use fork?

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Re: Long running CGI script

Quoted text here. Click to load it

Apache, and probably other web servers, will kill the CGI process once
the process closes STDOUT and STDERR.  That is probably why your script
is dying.  Either reconfigure the server not to do this (I don't know how
to do that) or fork a new process to do the heavy lifting so that the
original process can go away gracefully.

Quoted text here. Click to load it

Sorry, I can't make sense of this.  Can you show the relevant code?

Quoted text here. Click to load it

I'd prefer to stop aging, but that isn't working out for me, either :)


-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB

Re: Long running CGI script

xhoster@gmail.com wrote:
Quoted text here. Click to load it

  Are you on a win32 machine?  If so, Why can't you just code

   print "this may take awile...";

  I'm not really a Unix Perl guy, but "shell()" sounds familiar.


Quoted text here. Click to load it

 Try here:

Quoted text here. Click to load it

  Try looking at this page;

  Exec() and system()  seem appropos to your needs- but maybe I'm
misreading you.

 If what you need is a formal "callback" functionality, you might be
best served by using semaphores- as Perl isn't really an "event-driven"


Site Timeline