Question

That's about it. Is OB heavier than including a file?

Was it helpful?

Solution

Output buffering works in RAM. Hitting the filesystem may only hit RAM (cache), but it has the potential to hit the disks. Any time you hit the disks, you're looking at at least an order of magnitude of slowness compared to straight RAM access.

OTHER TIPS

I'd say depends on what's expensive on your system... if you absolutely must use the smallest amount of memory possible, then writing directly to disk may be your only option, although the underlying system's implementation of a 'disk write' will still write out in chunks when it can, since you're probably not calling 'write' for each character.

In the end, buffering within reason is faster... the easiest way to test is by writing out a large string of characters, one character at a time, then the string in a few reasonable chunks.

With that in mind, I can't think of why you wouldn't buffer your output at least somewhat! If all you're doing is copying a file from one place to another, using a system call (if available) is probably much faster than it would be reading, buffering and writing in PHP.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top