Re: How can I tell if an output stream is finished?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I don't think you can. Each element in a web page is transmited over a separate connection, when the browser parses an included element, such as an image, an iframe, a stylesheet, an included script file or whatever, it opens a new connection to the server (or another server in the same domain) and from then on, they run completely asychronous, any of them can finish at any time, depending on many factors completely out of you control (such as caching so that an element might be taken from the local cache instead of picked from the server, which wouldn't be the case with dinamically generated images as your situation, but I mention it just as an example).

So, the answer to the question in the subject line is no, you cannot, the thread serving your main HTML document might end before the server even started serving the included image, or the other way around, and once your script if finished, you have no further control. Holding your script until the image is served might get it hang forever, since the image might not even be requested, if taken from the browser cache on the client side, so you might be waiting forever.

If you want to clean up dynamically generated files, you have to do it via a cron job every so often. Another alternative is serving the included images via a separate script, thus you would have to have:

echo '<img src="imageserver.php?img=' , urlencode($rel_mapfile) , '" alt="Course Map">' , CRLF;

Then imageserver.php would pick the image, serve it and when it is finished you delete it, nevertheless, this takes more CPU time, so I would still take the other option.

If you can attach a script to the end of a session, and you put all dynamically generated content under a directory named after the SessionId, when the session is over, you delete the complete directory with everything it had. (I know IIS does that, but I never had to manage an Apache server, someone can help on that?). This one doesn't take any overhead on a per-page basis, just once per session and keeps the disk storage clean.

Just some sugestions, I hope they help.

Satyam


----- Original Message ----- From: "Al" <news@xxxxxxxxxxxxx>
To: <php-general@xxxxxxxxxxxxx>
Sent: Sunday, March 05, 2006 9:17 PM
Subject:  How can I tell if an output stream is finished?


I have a page that resizes an image to be included in a html page, using:

echo "<img src=\"$rel_mapfile\"  alt=\"Course Map\">\n";

unlink($rel_mapfile);

I need the other html stuff on the page so I need to fetch a file from the server to include in the page.

So, I resized the image and saved it as a file.  That works fine.

After sending the temporary resized file I want to delete it.

Obviously, an unlink($rel_mapfile) is executed before the echo "<img src=\"$rel_mapfile\" ... is finished.

Thanks....

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux