Summary
This chapter built on top of the foundation of both tools you can use to profile your PHP
application, and it also looked into the current PHP best practices, which can increase the
performance of your application, such as the following:
• Using require over require_once
• Calculating the length of a for loop in advance
• Using foreach instead of while and for when accessing elements
within an array
• Using fread() for small file data access and file_get_contents for
large files
• Accessing object properties faster
0.3730ms.
We will compare both methods, fread() as well as file_get_contents(), on two
scenarios, returning data as a string on a small 3.9KB file, and then returning the data
from a large 2.3MB file (Listing 3–14).