Large HTTP Posts - get corrupted or just hang - with fastcgi PHP
I use Freebsd 7.0 with lighttpd 1.4.19 and php-cgi 5.2.5 (with suhosin
patch). I run php-cgi with a external spawner.
I noticed, that when I do a large upload (1.2 megabytes) php works
unadequately: randomly it either corrupts the upload or just freezes.
So for instance, if I run php-cgi on a tcp port (1026) it successfully
accepts all uploads that are given to it from lighttpd and processes
them through the script. But randomly (sometimes several times in a row,
sometimes one out of 10 requests) it receives corrupted post data (several
bytes in the center of the 1.2 megabyte block get corrupted - replaced
with 00 00 00 hex values). Nothing freezes at this configuration.
If I run php-cgi as a unix socket (/tmp/php.sock) it either accepts the
upload (and never shows any sign of corruption, all data is processed
normally), or just halts and leaves the connection open (doesn't reply
to the current and any new connections either).
Sometimes it just unfreezes after a while and starts accepting new
connections, sometimes I just have to respawn php-cgi.
My best guess is that it might have something to do with the freebsd 7.0
socket handling. Maybe not - maybe it really is a bug in php-cgi or lighttpd.
Here is the command I use to make the upload from the remote host.
curl -vv -# -s -F "firstname.lastname@example.org" -H "Host: upload.host.ru" -H
"Expect:" -H "Content-Type:" -0 220.127.116.11:200/testupload.php
Note the empty Content-type - once I noticed the corruption, I decided
to make a test and debug HTTP_RAW_POST_DATA by hand. The corruption was
all the way up there.
The testupload.php script checks the HTTP_RAW_POST_DATA, extracts the
uploaded files from mime headers and checks it's md5 value. If MD5 is
incorrect, it logs the uploaded file and then I compare it to the normal
When I use "truss" (like strace) and attach to the lighttpd process, all requests get to the fastcgi unix-domain socket (/tmp/php.sock) without any problems. All code gets executed correctly, no hangs or corruption.
Once I turn off truss, lighttpd starts hanging the connection on random requests.
So I suppose that somehow lighttpd is related to the data corruption. And this corruption doesn't happen when I'm attached to the lighttpd process via truss.
Updated by Anonymous over 11 years ago
I have to confirm that bug. Very annoying for a stable release. POST requests reproducible hang the whole http server so I have to restart it. The writev setting fixed it for me but as I understand, this is optimized for a server doing large file transfers only. So for an all purpose webserver, thats a no-go.
Also available in: Atom