Most of my PHP apps have an ob_start at the beginning, runs through all the code, and then outputs the content, sometimes with some modifications, after everything is done.
ob_start()
//Business Logic, etc
header->output();
echo apply_post_filter(ob_get_clean());
footer->output();
This ensures that PHP errors get displayed within the content part of the website, and that errors don't interfere with header
and session_*
calls.
My only problem is that with some large pages PHP runs out of memory. How do I stop this from happening?
Some ideas:
- Write all of the buffered content to a temporary file and output that.
- When the buffers reaches a certain size, output it. Although this might interfere with the post filter.
- Raise the memory limit (thanx @troelskn).
Whats the drawbacks on each of these approaches? Especially raising the memory limit?