Vinod Sebastian – B.Tech, M.Com, PGCBM, PGCPM, PGDBIO

Hi I'm a Web Architect by Profession and an Artist by nature. I love empowering People, aligning to Processes and delivering Projects.

Advertisements




Output Buffering in PHP

Output buffering in PHP allows you to manipulate and control the output that is sent to the browser. This technique offers several advantages and functionalities that can enhance the performance and flexibility of your PHP scripts.

Advantages of Output Buffering

  • Headers and cookies can be sent at any point during script execution.
  • Compression and reordering of output buffers are possible, leading to better performance.

Enabling Output Buffering

You can enable output buffering for all scripts by configuring the output_buffering directive in the php.ini file.

Functions for Output Buffering

  • ob_start(): Starts output buffering in PHP.
  • ob_end_flush() and ob_end_clean(): These functions are used to stop output buffering and either flush or clean (discard) the buffer contents.
  • ob_flush() and ob_clean(): The flush() function sends the current output buffer to the browser, while ob_clean() empties the buffer.
  • ob_get_contents(): Retrieves the contents of the output buffer without clearing it.

Advanced Output Buffering Techniques

  • ob_start("ob_gzhandler"): Enables compression using the gzip library, achieving up to 90% compression ratio for output.
  • output_add_rewrite_var('param', 'value') and output_reset_rewrite_vars(): Useful for URL rewriting and manipulation within the output buffer.

Output buffering is a powerful feature in PHP that can be used to optimize the delivery of content and enhance the functionality of web applications.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x