开发者

How do I prevent duplicate headers when dealing with threads in PHP?

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 real开发者_如何学Pythonly 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.


Did you try session variables? You could set a session variable in each of the scripts when they are complete/successful and then check/wait to see if they are complete/successful in your main process.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜