Apache / PHP Output Caching

I am working on a PHP script that generates large (multi-MB) output "on the fly" without knowing the length in advance. I write directly to php://output via fwrite() and tried both standard output and using Transfer-Encoding: chunked (encoding chunks as needed), but no matter what I try, the browser waits until all the data will not be written before the loading dialog is displayed, I tried flush() ing also after the headers and after each fragment, but that also doesn’t matter.

I assume that Apache caches the output, as the browser usually displays after receiving a few kB from the server.

Does anyone have any ideas on how to stop this caching and clear data from the browser as it is created?

Thanks J

+7
php caching apache
source share
1 answer

First of all, like BlaM mentioned in his comment, if PHP's OutputBuffering is enabled, this will not work, so it would be useful to know your phpinfo ().

Next, try, if it works with a large file that is stored on the yor web server, output it in the readin file. And with that, check if you are sending the correct headers. Tips on how to read the file () and send the correct headers, indicated here: https://stackoverflow.com/a/4646268

And while you're on it, call ob_end_flush () or ob_end_clean () at the top of your script.

+1
source share

All Articles