Loading progress display with mod_fcgid using mod_deflate

When you run your processes with mod_fcgid under apache, one of the problems is that you cannot usefully run flush() to send buffered output through to the client. The reason for this is that the fastcgi interface doesn’t have the nangle algorithm, so it naïvely sends data once a 64kbyte block has been buffered. What this means is that code like this just doesn’t work:

<pre><?php passthru('
echo hello; sleep 5;
echo there; sleep 5;
echo all at once;')

Instead of sending output in three batches 5 seconds apart, it sends it all at once at the end.

However, there’s a work-around. If you’re using mod_deflate then whatever you send from your process to mod_fcgid is compressed before it is transmitted to the client. So you can do this:

<pre><?php passthru('
echo hello; dd if=/dev/zero count=128; sleep 5;
echo there; dd if=/dev/zero count=128; sleep 5;
echo all at once;')

That causes the data to be sent in three discrete steps. Even though there is a 64kbyte block of nulls transmitted from your PHP process to apache, apache compresses that down to under 1kbyte so it is never transmitted across the wire. The only way to tell that it’s there is to look carefully at your memory usage in the browser.

This entry was posted in Stuff and tagged , , , , , , . Bookmark the permalink.