Tip:
Highlight text to annotate it
X
>> HIGGINS: Hi, my name is Eric Higgins and I'm a Webmaster at Google. Webmasters at Google
are responsible for hundreds of thousands of Web pages. Because we have billions of
users, speed is extremely important to us. I've been coding PHP for the past eight years.
And over that time, I've come up with a few things. And I think it might help speed up
your PHP. Here you have a really simple PHP script that just pulls the list of users from
mySQL database. Then it prints them onto my page. Because of the way it's currently written,
changes to the script could cause a drop in performance. For example, making the SQL query
or the print seem is more complex or returning a large set of data from mySQL. Now, let's
make some changes to this script to make it run even faster. First, I'm going to change
my strings to use single quotes instead of double quotes. Using double quotes causes
the PHP engine to scan a string for nested variables and then replace them with their
value. Next, I'm going to change from using the print function to Echo. Since I'm using
Echo, I have the ability to pass as many arguments as I want. This allows me to change all of
my decimals to commas and skip the concatenation of the string. After just a few easy changes,
now I have a nice fast PHP script. To learn more about how to speed up your Website, go
to code.google.com/speed.