Question

I'm trying to develop an online management system for a very large FLAC music library for a radio station. It's got a beefy server and not many users, so I want to be able to offer a file download service where PHP transcodes the FLAC files into MP3/WAV depending on what the endpoint wants.

This works fine:

if($filetype == "wav")  {
    header("Content-Length: ". $bitrate * $audio->get_length());
    $command = "flac -c -d ".$audio->get_filename().".flac";
}

ob_end_flush();
$handle = popen($command, "r");
while($read = fread($handle, 8192)) echo $read;
pclose($handle);

and allows the server to start sending the file to the user before the transcoding (well, decoding in this case) completes, for maximum speed.

However, the problem I'm getting is that while this script is executing, I can't get Apache to handle any other requests on the entire domain. It'll still work fine on other VirtualHosts on the same machine, but nobody can load any pages on this website while one person happens to be downloading a file.

I've also tried implementing the same thing using proc_open with no difference, and have played with the Apache settings for number of workers and the like.

Is the only way to stop this behaviour to use something like exec and waiting for the encoding process to finish before I start sending the user the file? Because that seems sub-optimal! :(

UPDATE: it seems that other people can still access the website, but not me - i.e. it's somehow related to sessions. This confuses me even more!

Était-ce utile?

La solution

Use session_write_close() at some point before you start streaming... You may also want to stream_set_blocking(false) on the read pipe.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top