Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Note: admins, please vote for migration to ServerFault.

I'm using a LAMP setup with PHP running through mod_fcgid. For most requests this works well, but I've noticed that when I download a file but interrupt the download before it's complete, the php-cgi process that was serving the file blocks attempting to write more data until it the IPCCommTimeout is reached. Once the timeout is reached, the process gets interrupted and the process starts servicing other requests again.

Is there some available setting for fcgid that I can set to have it abort if nothing is capturing the output? Is there something I can do in PHP to handle it?

The problem doesn't occur if the download isn't interrupted; in fact, I only noticed it because I was trying to stream a FLV file using gddflvplayer, which seems to send a brief request to get the first few frames, then another to play it, and this causes the same problem.

FYI, this is the strace of the hanging cgi process; it sits like this until it's eventually interrupted, presumably by the process manager when the IPCCommTimeout is reached. My guess is that it's hanging trying to output the results of the readfile() call, but Apache is no longer listening (as the request has been cancelled by the user).

root@some-machine:~# strace -p 24837
Process 24837 attached - interrupt to quit
write(3, "\5|A\313%\35\337\376\275\237\230\266\242\371\37YjzD<\322\215\357\336:M\362P\335\242\214\341"..., 17432

The logs indicate that the request is eventually reaped due to the timeout

mod_fcgid: read data timeout in 240 seconds

The download code more or less just uses readfile to serve up the file, with a few headers involved as well (note: in this code, Header is more or less just a wrapper around header() to avoid problems in tests).

$filepath    = '/some/path/foo.flv';
$filename    = 'foo.flv';
$disposition = 'inline';

$h = Header::get();
$h->send('Pragma: public');
$h->send('Content-Transfer-Encoding: binary');
$h->send('Content-type: ' . FileSystem::get()->getMimeType($filepath));
$h->send('Content-Length: ' . FileSystem::get()->getFileSize($filepath));
$h->send('Content-Disposition: ' . $disposition . '; filename="' . $filename . '"');
$h->send('Content-transfer-encoding: 8bit');
$h->send('Expires: 0');
$h->send('Pragma: cache');
$h->send('Cache-Control: private');

flush();
readfile($filepath);
share
comments disabled on deleted / locked posts

merged by Marc Gravell Jan 25 '11 at 11:39

this question was merged with PHP + Fcgid hangs if download interrupted because it is an exact duplicate of that question.

migrated from stackoverflow.com Jan 25 '11 at 11:38

This question came from our site for professional and enthusiast programmers.

Browse other questions tagged or ask your own question.