need help, will pay

Discussion in 'Perl Misc' started by boman, Sep 2, 2009.

  1. boman

    boman Guest

    Need help with a simple Perl cgi script running from Apache 2.2 on
    Windows XP, willing to pay $100 for the solution. Please email me for
    details. Prefer NYC-based coder, payment in cash.
    boman, Sep 2, 2009
    1. Advertisements

  2. boman

    Nathan Keel Guest

    Why don't you post what the error is and the relevant portions of the
    script? You can probably get good help for no charge right now.
    Nathan Keel, Sep 2, 2009
    1. Advertisements

  3. boman

    boman Guest

    This question has been asked before, and I've tried almost all of the
    solutions, with no success. So I'm trying not to annoy this group by
    asking the question again. After the reading the "why doesn't this
    work" thread from Aug 20, I didn't want to start another brawl.

    But you graciously asked, Nathan, so here goes!

    1. display web page with simple form w/ radio buttons
    2. user selects radio button and clicks submit
    3. single parameter is passed from the radio button
    4. exe command on web server is initiated (I was using
    Win32::process), parameter is passed
    5. output of command is sent back to browser in real time (this is
    where I'm stuck)
    6. when command is done, start 2nd command, send output to browser in
    real time

    I've got 1-4 working, but cannot get output of command to the browser
    in real time, as the output is generated. It simply waits for command
    to finish, then sends the entire out put in one blob.

    Yes, I've got the $|=1 set, and I made sure apache is not buffering
    output, but can't get around the browsers doing the buffering (I think
    this is what's happening).

    Yes, I've read the stonehenge article which uses traceroute as an
    example, but cannot get that to work on my Windows perl v5.8.8. I
    tried some of the concepts from this article, but it's a bit out of my

    At this point I cannot spend much more time trying to get this to work
    myself, and I need a simple, yet professional level solution. I've
    read lots of forums, paged thru numerous books, I can't really spend
    time on that anymore. I need something that works, and I need it this

    I know this can probably be done in javascript, but I'd prefer this to
    be done in Perl. Also, I won't be able to install any modules, we'll
    have to use what's installed by default.

    boman, Sep 2, 2009
  4. boman

    Brian Wakem Guest

    A quick and easy way around browser buffering is to print something like
    this 100 or so times after every line you output.

    <!-- this wont show up on the page but will force the browser to flush -->
    Brian Wakem, Sep 2, 2009
  5. As has been explained to you back then this is _NOT(!)_ a Perl issue but
    a problem somewhere in the long chain of receiving CGI response,
    creating and sending HTTP response, receiving HTTP response, rendering
    the page in the browser. You really need someone who is familiar with
    those areas (no matter in which language) instead of someone who is
    familiar with Perl.

    In short: you are barking up the wrong tree.
    As I said, you need someone who is familiar with web programming, not
    someone familiar with Perl.
    That is not possible! Please, please, please, you already set the Perl
    buffer to auto-flush. There REALLY is nothing else you can do in your
    Perl code.

    You said yourself that the buffering probably happens in the brower.
    Maybe so, maybe somewhere else in the chain. But it really, really isn't

    Aside of that, "in real time" is a non-starter to begin with because the
    HyperText Transfer Protocol is not real-time to begin with.
    If you need real time then you need to look into a different protocol,
    but that's even more off topic than web programming.

    Jürgen Exner, Sep 2, 2009
  6. boman

    boman Guest

    Jürgen, I've read your previous posts and I respect your opinion, but
    I'm pretty sure what I'm asking for can be done in Perl, the
    stonehenge article with the traceroute example seems to prove that. I
    simply cannot spent any more time trying different things.

    Hence the offer of money; if someone can provide me with a solution
    based on the requirements (which include using Perl), than I will pay
    OK, not real time, how about updating the browser every 5 seconds? I
    actually do have something like this working, but I can't get around
    the browser buffer issue, and I'm pretty sure someone who knows Perl
    very well can provide a clever solution to get around that. I simply
    cannot spend any more time researching this, I need a solution now.

    boman, Sep 2, 2009
  7. boman

    Nathan Keel Guest

    I see, well then you might need to get someone to take a look or give
    you different options. There are some things you can try, but if
    you've set the buffering in the script, then the problem does lie
    elsewhere. You also might consider something like a server-push
    solution or just saying "click here to view the results", which can
    then open a file or read in the data as its happening (perhaps not via
    a CGI script).
    Nathan Keel, Sep 2, 2009
  8. boman

    boman Guest

    The link idea could be a fall back, but I'd like to automate that. I
    would think you can do that by setting the refresh parameter in
    cgi::pm's header call, but I cannot figure out how to get the refresh
    to exit once the process is complete, it just refreshes and refreshes
    and refreshes, even when the process completes. The stonehenge
    traceroute script gave me ideas, but I can't get it to work, and I'm
    out of time for troubleshooting.
    boman, Sep 2, 2009
  9. Ok, one final attempt:

    You are trying to haul a yard of sand with your pickup truck and it
    doesn't work. You keep trying to convince the car mechanic to finally
    fix the car while actually the problem is the washed out bridge to the
    sand pit.

    This is exactly what you keep doing. You are looking for a solution in
    Perl (your pickup) and keep asking Perl guys (your car mechanic) how to
    fix the program (your pickup) while actually Perl (your pickup) is doing
    just fine and the problem is not related to Perl (your pickup) at all
    and you should be asking web programmers (the DOT) about how to
    implement a non-bufferd path (fix the bridge).
    If you mean updating the displayed document rather than the browser,
    then HTML has such a directive, see "refresh" for HTTP-EQUIV. If that's
    a good choice I don't know, probably not.

    Jürgen Exner, Sep 2, 2009
  10. That is trivial to fix: for the final report, i.e. when the process is
    finished, just _don't_ set the refresh parameter in that final document.
    Problem solved.

    Jürgen Exner, Sep 2, 2009
  11. That should be simple, just don't send the meta refresh anymore
    with the last page when the program is done.

    The real problem is more that this can't be done with a simple
    CGI script because when the browser (re-)loads the page the
    web server will start a new CGI script that doesn't know any-
    thing about what happened before. So you will probably need
    some background process that waits for requests from the CGI
    script and then passes back the newly calculated data back to
    it (which the CGI script then sends on to the web server that
    transmits them to the browser).

    Since there could be several browsers asking simultaneously
    for new pages you also would have to be able to handle cal-
    culations in parallel within that background process. And
    you would have to rely on some mechanism, e.g. cookies, to
    know which results are for which client.

    Regards, Jens
    Jens Thoms Toerring, Sep 2, 2009
  12. boman

    boman Guest

    Here's the code so far. It continues to update the browser, although
    it's sloppy, and when the process is done, it does display the "done"
    page. But then it refreshes again in 5 seconds.


    use CGI qw/:standard/;
    use Win32::process;
    use Win32::process qw/STILL_ACTIVE/;
    use Win32;

    $| = 1;


    $counter = 0;
    while ($exitcode != 1) {
    if ($exitcode == 0) {
    print header, start_html,h4("something is wrong"), end_html;
    } else {
    print header(-Refresh=>"5"), start_html;
    print p("waiting, $counter secs... $exitcode "), end_html;
    $counter = $counter + 5;
    sleep 5;

    if ($exitcode = "") {
    print header, start_html, p("done $exitcode"), end_html;
    boman, Sep 2, 2009
  13. boman

    Nathan Keel Guest

    If you're happy with the result as it is and just don't want it to
    refresh, just pass a variable to the script that let's the script know
    that it's been refreshed (once) already and doesn't put in the refresh
    header in that resulting document's (web page) output.
    Nathan Keel, Sep 2, 2009
  14. boman

    Ron Bergin Guest

    Sloppy is an understatement.

    Why are you printing/reprinting the html header in a loop and why the

    You should execute that script outside of the cgi environment and
    remove the 'sleep' line to see why that's the wrong thing to do.

    Rather than using Win32::process, I think it would be better to use
    Ron Bergin, Sep 2, 2009
  15. Some (all?) versions of IE need 256 spaces first as start of the body.
    It's weird, but true. If your problem occurs in other browsers as well,
    this is not the solution, if your problem is only in IE, give it a try.

    Martijn Lievaart, Sep 2, 2009
  16. boman

    Ron Bergin Guest

    If you run the script from the command line, you'll see that the issue
    not that the browser is buffering the netstat output, the netstat
    command is buffering its output.
    Ron Bergin, Sep 2, 2009
  17. I think you haven't read the "stonehenge article" mentioned by boman.
    Here it is:
    No, the idea is to have a long-running process just write information to
    a file. The CGI script then just has to look at the file to determine
    what it should send back to the client.
    Just use several background processes.
    Query parameters are more reliable for that.

    Peter J. Holzer, Sep 4, 2009
  18. Jens Thoms Toerring, Sep 5, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.