Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Long running CGI script

Reply
Thread Tools

Long running CGI script

 
 
Stephen O'D
Guest
Posts: n/a
 
      06-17-2005
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.

Thanks,

Stephen.

 
Reply With Quote
 
 
 
 
Larry
Guest
Posts: n/a
 
      06-17-2005
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.

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      06-17-2005
"Stephen O'D" <> wrote:
> 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).


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.


> 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??!!).


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


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


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

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
kevindotcar@gmail.com
Guest
Posts: n/a
 
      06-18-2005


wrote:
> "Stephen O'D" <> wrote:
> > 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.
> >


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

print "this may take awile...";
system("myscript.pl");

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

[---]

> 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.
>
>

[---]

Try here:
http://perldoc.perl.org/File/Copy.html

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


Try looking at this page;
http://perldoc.perl.org/functions/exec.html

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"
infrastructure.


kDot

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having compilation error: no match for call to ‘(const __gnu_cxx::hash<long long int>) (const long long int&)’ veryhotsausage C++ 1 07-04-2008 05:41 PM
Running CGI from within CGI rodmc Python 3 02-14-2008 03:33 PM
what's wrong calling a Perl/CGI script in Perl/CGI script under Tomcat server? kath Perl Misc 4 04-09-2007 09:21 PM
modify a long-running python script while it is running? Benjamin Rutt Python 2 12-20-2005 01:42 PM
How long is too long for cgi script? el_roachmeister@yahoo.com Perl Misc 3 04-23-2005 03:30 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57