05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example 13-6. Output buffering to handle errors (continued)<br />

ob_start( );<br />

?><br />

Results!<br />

Here are the results of your search:<br />

<br />

<br />

<br />

<br />

<br />

In Example 13-6, after we start the element, we register the error handler and<br />

begin output buffering. If we cannot connect to the database (or if anything else goes<br />

wrong in the subsequent <strong>PHP</strong> code), the heading and table are not displayed.<br />

Instead, the user sees only the error message, as shown in Figure 13-1. If no errors<br />

are raised by the <strong>PHP</strong> code, however, the user simply sees the HTML page.<br />

Figure 13-1. Error message instead of the buffered HTML<br />

Performance Tuning<br />

Before thinking much about performance tuning, get your code working. Once you<br />

have working code, you can then locate the slow bits. If you try to optimize your<br />

code while writing it, you’ll discover that optimized code tends to be more difficult<br />

to read and to take more time to write. If you spend that time on a section of code<br />

that isn’t actually causing a problem, that’s time that was wasted, especially when it<br />

comes time to maintain that code, and you can no longer read it.<br />

Once you get your code working, you may find that it needs some optimization.<br />

Optimizing code tends to fall within one of two areas: shortening execution times<br />

and lessening memory requirements.<br />

308 | Chapter 13: Application Techniques<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!