Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Is CGI.pm my best choice?

by dru145 (Friar)
on Dec 04, 2001 at 22:57 UTC ( [id://129405]=perlquestion: print w/replies, xml ) Need Help??

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

Howdy Monks,

Let me start off by saying that this is my first CGI script, but I have written quite a few perl scripts in the past. I wrote a web interface (with CGI.pm) which produces a report from our firewall logs for certain criteria which the user defines (ie. ip address, port number, date, etc). It works fine when it is a small report that only takes 5 minutes or less, but if it has to parse a large amount of traffic over many log files, the script timesout before it is complete. I have a few questions:
  1. Does the webserver (apache in this case) control the timeout of a CGI program or can this be configured in the cgi program?
  2. Is there a way to have the script stay running even if I close the browser? Right now if I close the browser, it kills the script.
  3. Last. Might it be a better idea to use mod_perl instead? I've been reading up on mod_perl and it seems to be good if you are a little more advanced in Perl (which I don't feel I am yet) and it has more options then CGI.pm

TIA
-Dru

Replies are listed 'Best First'.
Re: Is CGI.pm my best choice?
by dws (Chancellor) on Dec 04, 2001 at 23:07 UTC
    It works fine when it is a small report that only takes 5 minutes or less, but if it has to parse a large amount of traffic over many log files, the script timesout before it is complete.

    Does the script time out, or does the browser time out waiting for a response from the web server? If the latter, then your script needs to turn off buffering, and arrange to emit some form of periodic "I'm still alive" message to the browser while you're parsing log files. One non-obtrusive way of doing this is to periodically print an HTML comment. This can double as debug info, allowing you to see trace info from your script by viewing source.

    Try this: as you begin parsing each new log, do   print "<!-- $logfilename -->\n"; This will help keep the browser from timing out on you.

Re: Is CGI.pm my best choice?
by mitd (Curate) on Dec 05, 2001 at 01:13 UTC
    First a few non-perly fundmentals:

    The following happens after browser has made a connection.

    1. The Apache TimeOut directive controls when the webserver will give up and close connection when waiting to recieve data (from browser) or send data (static or cgi generated data). The TimeOut default in my version of Apache is 300 seconds.
    2. The human controlling the browser can also kill connection via STOP button or killing browser.
    ... It works fine when it is a small report that only takes 5 minutes or less, but if it has to parse a large amount of traffic over many log files, the script timesout before it is complete.
    Looks like you are hitting the 300 second limit. So you can either up the TimeOut value (don't forget to reboot apache :) ) or use a different approach like some the suggestions already given. I beleive that it is never a good idea to keep user waiting. So what I have done with these types of long running 'Admin' type functions is to either create cron driven scripts that produce static report pages, or scripts that munge data down to a form that can be quickly transformed ie data->XML->XSLT->HTML. There is also a high bred method that I use when info is needed realtime up to the minute; scheduled preprocessing, cgi only recent data.

    Good Luck

    mitd-Made in the Dark
    'Interactive! Paper tape is interactive!
    If you don't believe me I can show you my paper cut scars!'

      I believe that it is never a good idea to have user waiting.

      Not quite what you meant by "waiting", but merlyn has a column that describes how to give users periodic feedback on long searches.

      Yup, right on! If you do have to make'em wait let them know whats going on. My point ( not really well made :) ) was alot /perhaps most of the time these kinda problems don't need realtime processing.

      mitd-Made in the Dark
      'Interactive! Paper tape is interactive!
      If you don't believe me I can show you my paper cut scars!'

Re: Is CGI.pm my best choice?
by arturo (Vicar) on Dec 05, 2001 at 00:17 UTC

    mod_perl and CGI.pm aren't mutually exclusive; mod_perl embeds a Perl interpreter in the Apache binary; apart from saving the overhead of starting the interpreter and compiling the Perl script for each time it is requested, it also gives you 'hooks' into the handling of the request. So it's faster and far more powerful than traditional CGI scripts (which run outside of the web server and typically only communicate with it via the environment variables), but by itself it doesn't parse user input or generate HTML. Of course, in a mod_perl environment it makes sense to implement a templating system, so you may not need the latter.

    I mistrust all systematizers and avoid them. The will to a system shows a lack of integrity

Re: Is CGI.pm my best choice?
by fuzzysteve (Beadle) on Dec 04, 2001 at 23:16 UTC
    1. I think its generally the browser that controls the timeout. You can keep it running by continuing to pass data to it (print some characters occasionally. possibly in a comment) the server can deal with it, but unless its all the server does it's probably not a great idea increasing the timeout. if you do it'll affect all the other pages as well.
    2. have the cgi-script act as a bootstrap for the actual script that does the work (exec the program. rather than system; if the cgi script is terminated (the browser is closed) the children would be killed.) (i think)
    3. Hmm, havn't read much about mod_perl, probably worth using if you use the script a lot, otherwise , i'm not so sure.

    Take a look at Detect Stop Button for preventing timeouts. Its not the primary focus of the node, but its mentioned
Re: Is CGI.pm my best choice?
by lestrrat (Deacon) on Dec 04, 2001 at 23:32 UTC
Re: Is CGI.pm my best choice?
by mce (Curate) on Dec 05, 2001 at 16:25 UTC
    Hi,

    If you have a CGI that takes a long time, I suggest to use Randal's suggestion, which is described here

    Just my 0.02$ worth.


    ---------------------------
    Dr. Mark Ceulemans
    Senior Consultant
    IT Masters, Belgium

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://129405]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-25 07:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found