X-LIGHTTPD-SENDFILE sometimes responds with truncated jpgs
Added by carpii over 14 years ago
I have a php script which serves up thumbnail images, using lighty 1.4.28
This script previously used fpassthru to serve the image files, but I recently switched to using X-LIGHTTPD-send-file.
Since then, I occasionally see jpgs where the image ends prematurely, and the rest is grey pixel area. Im having a hard time understanding what causes this, its like the response is ending prematurely. Forcing a refresh of the images in the browser, usually loads the image fully.
This effect has been seen in latest Firefox and Chrome.
Checking lighty access log for an image which failed, the log does suggest the full image data is being sent (ie in the response size, in bytes matches the file size)
The server is Centos 5.5 (32-bit), and is not under any particularly heavy load.
Lighty is serving up an average of 80 requests/sec on this server, the majority are via the image php script, but there are also some static jpgs and gifs which are not served via a php script.
Any suggestions welcome, thanks
Code to serve images (the script is fairly lightweight, with just some path manipulation and no database hit). I set $etag to be just the image filename, since the images never change
header("Content-type: image/jpeg"); header("ETag: \"" . $etag . "\""); header("Last-Modified: Thu, 01 Jan 2004 00:00:00 GMT"); header("X-LIGHTTPD-send-file: " . realpath($filename));
Relevant bits of lighty config....
server.max-keep-alive-requests = 50 server.max-keep-alive-idle = 5 server.max-read-idle = 15 server.max-write-idle = 15 server.max-fds = 2048 fastcgi.server = ( ".php" => (( "allow-x-send-file" => "enable", "bin-path" => "/usr/local/bin/php-cgi", "socket" => "/tmp/php-fastcgi.socket" + var.PID, "max-procs" => 1, "bin-environment" => ( "PHP_FCGI_CHILDREN" => "256", "PHP_FCGI_MAX_REQUESTS" => "10000" ), "bin-copy-environment" => ( "PATH", "SHELL", "USER" ), "broken-scriptfilename" => "enable" ))) server.max-worker = 1 etag.use-inode = "enable" etag.use-mtime = "enable" etag.use-size = "enable" static-file.etags = "enable"
Replies (4)
RE: X-LIGHTTPD-SENDFILE sometimes responds with truncated jpgs - Added by Olaf-van-der-Spek over 14 years ago
Are the image files being updated while being served?
RE: X-LIGHTTPD-SENDFILE sometimes responds with truncated jpgs - Added by carpii over 14 years ago
No, the images are just uploaded once by user, and from then on they are never changed or modified
Icy asked me to find out if the Content-Length in the HTTP response, matches the file size.
Its taken a while to confirm this, but finally I managed to see the problem while I had firebug open.
In this case the image on the server is 40357 bytes. This is the same value which appears in the access log, and also the value in Content-Length in the HTTP Response. Yet the image was still about 60% complete, then the rest appeared as grey (corrupt)
I can confirm the image on the server is not corrupt, and forcing a reload loaded the image fully (with same byte size).
Im not sure what else to check for :(
Any ideas please?
RE: X-LIGHTTPD-SENDFILE sometimes responds with truncated jpgs - Added by mikn over 14 years ago
carpii wrote:
No, the images are just uploaded once by user, and from then on they are never changed or modified
Icy asked me to find out if the Content-Length in the HTTP response, matches the file size.
Its taken a while to confirm this, but finally I managed to see the problem while I had firebug open.
In this case the image on the server is 40357 bytes. This is the same value which appears in the access log, and also the value in Content-Length in the HTTP Response. Yet the image was still about 60% complete, then the rest appeared as grey (corrupt)I can confirm the image on the server is not corrupt, and forcing a reload loaded the image fully (with same byte size).
Im not sure what else to check for :(
Any ideas please?
We had a similar problem and as it turns out the problem was that we had zlib.output_compression on globally, you can turn it off in the script serving the images and it might fix the problem.
RE: X-LIGHTTPD-SENDFILE sometimes responds with truncated jpgs - Added by stbuehler over 14 years ago
lighttpd will fix the Content-Length header in case of X-Sendfile (since 1.4.19), and will drop any content from the php backend.