I feel boneheaded asking this, because I am probably overlooking the obvious, but it's bugging me.

I have written a script that runs from a webserver and is controlled/executed through the browser. Because of the length of time that can be involved in running the script from beginning to end, it forks off and sends a simple "The program is running" message to the user. As the script is running, it logs its actions to a file that can be viewed from the script's control panel. The idea is that the user can check the log every once in a while to monitor progress and see when the script has completed execution. The problem is, the log is not being written in anything even approaching realtime. All the writing seems to be getting done in 4096 byte increments. When I have the script output text directly to the browser, I experience no such delays.

All I can think of is $|, but I have that set to a positive integer (1). I am not flocking the file (I had been, but both flock, 1 and flock, 2 resulted in the user having to wait for the script to run its course before viewing the log.

Right now, I am dancing around the problem by having the program close and re-open the log file at the beginning of each loop iteration but that seems like a silly way to go.

What's really driving me crazy is I used a nearly identical fork/log setup for a program in the past and it worked fine. Now I can't find that code anywhere, so I can't compare it with my current project. It's this part that leads me to believe I am overlooking some glaringly obvious point.

The problem is hardly fatal, but I hate not understanding what my program is doing. Any information on how to fix this would be appreciated.

Thanks, SpaceAce


In reply to Delayed writes by SpaceAce

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.