I have a temporary image file that is generated by a script It then is loaded by the browser in the output of the script (e.g. <img src="temp_Ad934C.gif">). However, it needs to be deleted after it is shown. I could do this by replacing the filename of the image by a script that deletes the file after it is run (e.g. <img src="deleteaftershown.pl?temp_Ad934C.gif">) but this is too sensitive for hazardous attacks. I tried to use an END block that is executed after the main script is executed and it deletes the tempfile after 5 seconds. However when running this, the browser first waits 5 seconds before displaying the page. This is obvious as the script is still running. How can I force Perl to end the connection with the browser but keep running the script?
END { #delay delete tempfile my $oldtime = (time + 5); my $i=1; while ($i==1) { if (time > $oldtime) { $i=0; if($tempfile ne "") { unlink($tempfile) } } } }

In reply to Keep running script but ending it to the browser by cowgirl

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.