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

Hello monks, here's my question: I wrote a script that generates a text file of arbitrary length (but usually in the range of 4000 lines or so). The text consists of commands for a program called PAUP* and it's in the nexus file format for phylogenetic inference. Anyway, that's not important right now. What's important is this: the script runs just fine from the command line, but I want to run it as a CGI program so that the user can input some settings for the PAUP* commands using an HTML form and the script subsequently spits out those 4000 lines. I got that to work in so far that it properly starts printing out the text (either to a browser window, or if I roll my own MIME-type, e.g. Content-type: text/nexus, to a file) but usually not till completion. For example, I get the first 2000 lines, but not the rest? What do I do? I am running apache under cygwin, and, although I can poke around in httpd.conf to my heart's content I'd rather not. Thank you for any replies.

Replies are listed 'Best First'.
Re: incomplete cgi output
by CountZero (Bishop) on Feb 05, 2004 at 06:49 UTC
    Did your CGI-script end with an error? What does the Apache error log show? Is your script very slow (in other words does it run for a long time before finishing the file)?

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      Did your CGI-script end with an error? What does the Apache error log show? Is your script very slow (in other words does it run for a long time before finishing the file)?

      Hey! Thanks for responding. The cgi script runs fine on its own (i.e. no errors or anything, I use strict and warnings, and the output is valid if I echo from stdout to a file and check it out). The error log doesn't show anything. The only thing I can think of is that the script is indeed kind of slow - depending on the user's settings it may take up to a few seconds to process. When I try it out so that it creates small output (a few hundred lines) it usually works fine (also no errors).
        A "few seconds" should be OK for Apache, unless the time-out value has been set extremely low. I have written scripts which perhaps take 10 seconds or more to conclude without problems (other than users repeatedly hitting the refresh button -- impatient lot they are).

        Did you check whether the script really stopped prematurely or whether it was something else that caused it to fail to send all its output to the client? Perhaps if you simultaneously print some debug info to a file (such as a number or timestamp every x lines printed), you can see whether the "break" is in the script (the script did not ran all the way to the end) or somewhere else (the script did ran all the way, but Apache choked on its output halfway through).

        CountZero

        "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: incomplete cgi output
by matthewb (Curate) on Feb 05, 2004 at 14:48 UTC

    It may, of course, be that there is something wrong with your code but if, as you imply, this is a timing-out issue then the canonical solution is to serve a `please wait' script with a refresh instruction in the header while your file is being written. The intermediary script checks the output progress and serves a download link on completion.

    This technique has been explained with example code by merlyn in one of his famous Web Techniques columns.

    MB