I've written a PHP script that has to fork and do some processing in parallel, and then the main page returns data after processing. I'm currently using the pcntl functions to do this. I need to run anywhere between 2 and 10 threads to work in parallel, and I have to wait until I get a result from all of the threads before the script outputs to the browser.
Unfortunately, I find that I have multiple "Content-Type" headers appearing in the output:
Content-Type: text/plain
Content-Type: text/plain
Content-Type: text/plain
[... actual content ...]
It seems to be one header per thread spawned. I've tried to close STDOUT
via fclose(STDOUT)
before processing, and I've tried surrounding everything by output buffering to no avail. I haven't yet found anyone else with this problem, so either nobody is trying to do it or I'm doing something that's off the beaten track.
I'm really looking for either ways to stop this happening, or suggestions on alternative ways to get this done.
The server is set up to use PHP as CGI under mod_suPHP, if that makes any difference.