Scaling Control Structures

In addition to caching, proper use of loop control structures found in PHP can dramatically speed up an application. Suppose that a simple array needs to be iterated over and something done to all of the array elements as described in the following code.

This use of sizeof is considered normal by many but wastes CPU cycles. While one instance of such waste may not have a dramatic impact on the scalability of an application, if such for loops are embedded in other for loops, the wasted cycles add up quickly. Such waste, though small in each instance, dramatically impacts the scalability of a large application. In the following code loops of two types are used, timed, and compared. Figure 1-1 shows the output.

FIGURE ...

Get Oracle Database Ajax & PHP Web Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.