Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
PHP Streaming and Output Buffering Explained
Sep 04, 2014 @ 10:17:44

The SitePoint PHP blog has a new performance-related post to the site today from Imran Latif. This new post looks at effective use of output buffering and streaming and explains how it works and some examples of its use.

As a PHP developer, I was wondering whether we can have something similar [to Streaming in Rails] in our favorite language? The answer is yes – we can easily have streaming in PHP applications with little effort, but in order to get this right we have to become familiar with some underlying concepts. In this article, we will see what streaming is, what output_buffering is and how to get our desired result under different webservers (Apache, Nginx) and PHP configurations (CGI, mod_php, FastCGI).

He starts off with a comparison of the two different methods, streaming and output buffering, and how they behave in the output of content. He then gets into some simple examples with PHP with various methods: a simple delay, chunking up output and finally using the actual output buffering handling PHP offers. He also includes an example of streaming content over an Ajax request with a simple test using the sleep function.

tagged: streaming output buffering tutorial introduction beginner ajax

Link: http://www.sitepoint.com/php-streaming-output-buffering-explained/

PHPBuilder.com:
Six Cool PHP Tricks You May Not Know
Apr 23, 2010 @ 08:44:24

On PHPBuilder.com there's a new article with a few things - six things, to be exact - that you might not know about the PHP language as written up by Chris Roane.

Over the years I've come across some useful tricks in PHP that are not obvious, but are worth mentioning. This is not meant to be a comprehensive list of all the useful tricks that you can do with PHP.

The list of six includes:

  • Count Characters in a String
  • Use Single Quotes When Possible
  • Use Arrays in Form Fields
  • PHP Output Buffering
tagged: trick quote array output buffering

Link:

DevShed:
Using Timers to Benchmark PHP Applications
Apr 30, 2008 @ 14:31:08

DevShed has posted the second article in their series looking at benchmarking your PHP scripts. This time they look at the use of "timers" to check on script execution length.

Since you already know how to create timer functions and classes, in this tutorial, I'll create some concrete examples that show where these timing mechanisms can be applied in order to evaluate the performance of certain PHP applications.

They create a few classes that connect to a database and pull out rows (handing it off to a Result class). They use these classes in two examples - one with compression (output buffering) and one without using their Timer class to evaluate the differences.

tagged: timer benchmark application tutorial class mysql row output buffering

Link:

Arnold Daniels' Blog:
How I PHP: The Output Handler
Nov 16, 2007 @ 11:17:00

Arnold Daniels has a quick little tutorial posted to his blog about using the output handler in PHP (one of what he considers a technique that's "missing out" from normal PHP use). His example involves buffering the common page parts - like a template.

A website usually has a part which is common across all pages, containing the HTML header, the menu and those kinds of things. This is often solved in one of four ways. [...] All of these methods work, however there is a better way to solve this. You guessed it, by using an output handler.

He links to an example he's created and includes the code for his OutputHandler class to make controlling the content easier.

tagged: output buffering handler tutorial template output buffering handler tutorial template

Link:

Arnold Daniels' Blog:
How I PHP: The Output Handler
Nov 16, 2007 @ 11:17:00

Arnold Daniels has a quick little tutorial posted to his blog about using the output handler in PHP (one of what he considers a technique that's "missing out" from normal PHP use). His example involves buffering the common page parts - like a template.

A website usually has a part which is common across all pages, containing the HTML header, the menu and those kinds of things. This is often solved in one of four ways. [...] All of these methods work, however there is a better way to solve this. You guessed it, by using an output handler.

He links to an example he's created and includes the code for his OutputHandler class to make controlling the content easier.

tagged: output buffering handler tutorial template output buffering handler tutorial template

Link:

LoopPo Blog:
PDML PHP tricks
Mar 01, 2007 @ 10:48:00

A new post on the LooPo blog points out a handy PHP library to make and work with PDF files in PHP - Portable Document Markup Language (PDML).

I was curious how this works, as it seemed pretty different from previous similar libraries (PDFLib, FPDF), that offered a programmatic API to generate PDF DOMs instead of a markup language.

They describe how it works, what's included with the download and how it uses output buffering to get the job done as well as a few updates and further tips on its usage.

tagged: pdml tricks portable document markup language pdf output buffering pdml tricks portable document markup language pdf output buffering

Link:

LoopPo Blog:
PDML PHP tricks
Mar 01, 2007 @ 10:48:00

A new post on the LooPo blog points out a handy PHP library to make and work with PDF files in PHP - Portable Document Markup Language (PDML).

I was curious how this works, as it seemed pretty different from previous similar libraries (PDFLib, FPDF), that offered a programmatic API to generate PDF DOMs instead of a markup language.

They describe how it works, what's included with the download and how it uses output buffering to get the job done as well as a few updates and further tips on its usage.

tagged: pdml tricks portable document markup language pdf output buffering pdml tricks portable document markup language pdf output buffering

Link:

Riff Blog:
Console encoding in PHP-GTK apps
Nov 20, 2006 @ 10:58:00

PHP-GTKers working in English-related applications, don't have a problem with debugging messages output to a console when debugging, but applications on a more international front have issues with their output. But help has been found in this new post on the Riff Blog - a method for correctly encoding PHP-GTK applications.

PHP scripts are typically stored under UTF-8 encoding to limit i18n headaches, while the console in which their output will be displayed is normally configured to some regional encoding, like IBM850 in Windows/XP French.

So we need a workaround...

He splits the process out into a few steps, each with its own explanation and code:

  • Builtin tools
  • Buffering
  • Flushing
  • PHP-GTK is not PHP for the Web
  • Auto-flushing
All wrapped up with a final solution - using the iconv functionality in combination with some output buffering to correctly display the message.

tagged: phpgtk encoding output console i18n buffering iconv phpgtk encoding output console i18n buffering iconv

Link:

Riff Blog:
Console encoding in PHP-GTK apps
Nov 20, 2006 @ 10:58:00

PHP-GTKers working in English-related applications, don't have a problem with debugging messages output to a console when debugging, but applications on a more international front have issues with their output. But help has been found in this new post on the Riff Blog - a method for correctly encoding PHP-GTK applications.

PHP scripts are typically stored under UTF-8 encoding to limit i18n headaches, while the console in which their output will be displayed is normally configured to some regional encoding, like IBM850 in Windows/XP French.

So we need a workaround...

He splits the process out into a few steps, each with its own explanation and code:

  • Builtin tools
  • Buffering
  • Flushing
  • PHP-GTK is not PHP for the Web
  • Auto-flushing
All wrapped up with a final solution - using the iconv functionality in combination with some output buffering to correctly display the message.

tagged: phpgtk encoding output console i18n buffering iconv phpgtk encoding output console i18n buffering iconv

Link:

ThinkingPHP:
Issues with output buffering in CakePHP
Jul 17, 2006 @ 06:13:16

If you're using the CakePHP framework and are having a problem with output buffering, this quick tip on the ThinkingPHP blog might work for you.

Output buffering is a useful way to accomblish things in php like gzipping all html output and such. A while ago I wrote about it on this blog (see "A miracle called gzip") as well.

The reason I write about it again is, that I have discovered a little issue with it in CakePHP.

He notes that if you just use the ob_start with the gzip handler, debug issues arise. The soultion he's come up with, though, isn't quite as simple, but gets the job done in about ten lines and is easy to drop in anywhere.

tagged: cakephp framework output buffering gzip debug cakephp framework output buffering gzip debug

Link: