in reply to Re: Keep running script but ending it to the browser
in thread Keep running script but ending it to the browser

I am now using this:
END { system "nohup sleep 15 ; echo test >/dev/null 2>&1 &"; }
However inside the shell if the script is executed, it ends succesfully but then waits for 15 seconds before returning to the shell. Inside the browser the same thing happens, exactly 15 seconds after requesting the page, the page is returned. To see the problem I have added a time counter and the runtime is only around 0.2 seconds but it takes 15.2 in reality. Am I implementing the code wrong?

Replies are listed 'Best First'.
Re^3: Keep running script but ending it to the browser
by Perlbotics (Archbishop) on Aug 07, 2008 at 19:56 UTC
    Your first approach didn't look that bad (okay, I would suggest a sleep 5; instead of busy-waiting / saves some CPU). Anyway, the browser keeps waiting because it waits for further HTTP data on a still open TCP connection. If you can manage to close the connection before waiting to remove the file, shouldn't that fix the problem?
    Another Idea: Unless the temporary GIFs must be removed immediately, why not let them live for a while until the next invocation of your program? At the end of your program use stat() to remove all of your GIFs from previous runs whose ctime is older than than the maximum lifespan. Alternatively, you can run a small daemon to keep the directory clean. Should work for low traffic scenarios.