PHP Content-length header delays loading -



PHP Content-length header delays loading -

i have php webpage takes blob database , outputs image. when user uploaded image stored filesize (e.g. 491099) database.

when image requested through webpage add together watermark, set http headers , output image through imagejpeg($img). problem when image loaded (takes no time) browser still seems "busy" (loading indicator rotating). when requesting page through asynchronous phone call makes loading time long well, though image loaded within no time.

when remove content-length header, image loaded before browser stops right when it's loaded process time fast.

so seems browser thinks (due content-length header) should still loading while it's not...

removing content-length header no alternative since required in many browsers i've read.

// set header image header("content-length: " . $image->imagesize); //would 491099 in illustration header("content-type: " . $image->imagetype); header('content-disposition: inline; filename=" '. $image->imagename . '"'); $watermark = imagecreatefrompng('../images/watermark.png'); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $dest_x = ($image->imagewidth - $watermark_width) / 2; $dest_y = $image->height - $watermark_height - 5; $img = imagecreatefromstring($image->image); imagecopymerge($img, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 55); imagejpeg($img);

(note $image object of custom image class created holds info regarding image.)

anyone has thought why having behaviour?

thanks!

try instead:

ob_start(); imagejpeg($img); // should real image size $size = ob_get_length(); header("content-length: " . $size); // send ob_flush();

php http-headers content-length php-gd

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -