Strange behaviour of generated images
| From: | Victor V. Evtushenko | Date: | Tue, 17 Dec 2002 17:51:20 +0000 |
| Subject: | Strange behaviour of generated images | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-128590@lists.php.net to get a copy of this message | ||
Hi,
I'm trying to output a set of image thumbnails in HTML table. Everything
works fine, except that performance is very poor. If I put all the
thumbnails as regular files in some directory it has expected speed. But
if I'm trying to use script to retrieve thumbnails from their actual
location (which may be database for example) speed drops down
dramatically. And what is even more strange, from apache log I see that
script is terminating very fast, less than 0.5 second for each image
(they are relatively small, ~2K), but browser is spending huge amount of
time "downloading" images two at a time.
Image retrieving script is very simple:
<?php
$expires = 24 * 60 * 60;
$gm_expires = gmdate('D, d M Y H:i:s', time() + $expires);
header("Cache-control: public, max-age=$expires, pre-check=$expires");
header("Expires: $gm_expires GMT");
$filename = DATA_DIR . '/' . $_REQUEST['ID'];
$fp = @fopen($filename, 'r') or die ("Cannot open file $filename");
$story = fread($fp, filesize ($filename));
$packet = new Packet($story);
$content_type = substr($packet->value('IMAGE_FILENAME'), -3);
header("Content-type: image/$content_type");
header("Content-length: ". strlen($packet->value('IMAGE_REGULAR')));
echo $packet->value('IMAGE_THUMBNAIL');
fclose($fp);
exit;
?>
and call for images is made like this:
echo "<a href='$url' target='story'><img
src='show_image.php?ID=$id&s=0' width=65 border=0></a>";
Does anyone has such a problem before and is there any solution?
Thank you,
Victor.
--
Infodesk S.A.
Gustavo Mejia Ricart #70
Santo Domingo, Dominican Republic