I am writing an application in PHP, and I decided to do my own testing myself to determine how much PHP handles buffers and buffering. In particular, I wanted to see if manually calling ob_start() and ob_flush() have a huge impact on my program.
I called 10 KB Lora ipsum and went to work. I set a timer in PHP at the beginning and at the end of the for loop, which writes 10 Kbytes of lip (on the display: no div blocks) 100 times, for a total of 1 MB of data, which I thought would be enough work for a random CPU the download didn’t delete my data too much.
In addition to the PHP timer, I opened Chrome’s open source developer tools (F12) and wrote down the “time” and “timeout” fields. If I have the correct terminology, “time” is the total amount of time the page took to respond, and render and “latency” is just the time until the page first receives data from the server.
So, here is the secret: When I do nothing, but I write 10kB of 100x lip, my average values are:
PHP Time: 0.00630ms Chrome Time: 565.6ms Chrome Latency: 28.3ms
When I call ob_start() at the very beginning and ob_flush() at the very end:
PHP Time: 0.00792ms Chrome Time: 540ms Chrome Latency: 33ms
HOWEVER, and here's the secret - when I call ob_start() and ob_flush() at the beginning and end of each block of text 10 KB, my delayed delays are 4 times delayed.
PHP Time: 0.005814ms Chrome Time: 624.7ms Chrome Latency: 134.9ms ???
As far as I know, chrome latency should be cut to 100x since I clear the 1/100 path buffer through PHP output. I know that ob_start() and ob_flush() work on a higher buffer and they actually merge into a lower buffer, I would expect the lower buffer to be flushed at the same intervals, that is, I would see about the same a delay.
My test setup is a very modest Intel ATOM netbook with NVIDIA ION graphics, Windows 7 home premium (32-bit) and WAMPserver running under Apache 2.2.22 with quite a few default settings. I used Chrome 24.0.1312.52 m. The processor load was moderate, but not 100% during the tests, and my drum was almost empty.
Verification Code: http://pastebin.com/zf62Y4yz
Thanks!