PHP is the coding language which drives some of the biggest website platforms out there from Wordpress to X-Cart. So how can you make sure your PHP isn't messing up your SEO?
OK - first of all this is for techies. If you are not a PHP programmer this will all go way over your head.
Second if your thinking "I need to do this so I need to hire a programmer" first run a couple of checks. The improvements you make to PHP are very much about improving page speed loading. Google and other search engines will reward you with higher rankings if your pages load faster than those of your competitors ... when all other things are equal such as the quality of the content and the on-Page SEO.
I'd better just say those things because you're not going to get to the top of the search results with poor quality content, or even pretty good content if its badly search engine optimized so search engines can't understand what its about.
So anyway - Google uses Mobile First Indexing. It rewards you if your pages display well on mobile devices and load fast, even on slow Internet connections.
PHP is the code which generates each page for a website and the longer it takes to run that code the longer it takes for visitors to see it.
But be aware that this should be the last thing on your list when it comes to page loading speed work. You really want to follow the 80/20 rule. 80% of your loading time is coming from 20% of your page and that's rarely a PHP issue. More often its because your images are too large or your server is slow or your not using a server caching feature like LiteSpeed.
You can even tell the browsers of your visitors to remember (cache) things for a certain amount of time which will speed up loading for returning visitors.
So in my experience there are loads and loads of opportunities out there that need to be taken up before you get to PHP. I've put the full rundown in How to SEO your page loading speed.
When you've done all of that and you run it through the Google Lighthouse Performance Audit you might find yourself with a page loading score of 100%.
That doesn't mean its time to take a snooze and forget about PHP. If you are in a competitive market then all your competitors will be getting 100% as well and you need to be faster than them so time to see what you can do via PHP improvements.
We're going to follow the 80/20 rule again. 80% of the delays are caused by 20% of the code. To identify which parts of a page's PHP are slow I start by breaking down the code into blocks and using microtime like this:
This will print out to the screen how long it took to execute the block of code. If I break a page into four blocks then its usually pretty easy to find which part might have issues. If you have buckets of code you might need to then break that block down into smaller blocks. All a bit of detective work to find the few lines of code that are fouling things up.
Repetition is the first guilty area. You go through an array to find something or create a refined array. Then you go through that array again to find something or create a different refined array when you could have done all that the first time you went through the array.
If all the above was part of a function that gets called dozens or hundreds of times all that repetition time starts to add up so a good place to look for delays are in functions. Go through them, comment them up if they are new to you because that'll help in the future, and then just use your knowledge to spot repetitive code.
Poor SQL database calls are also a common issue. Let's say on one page you want to create a list of music albums along with the year they were published. Your database table also includes the musicians, writers, album cover graphics and so on but you don't need all of that. However your SQL syntax asks the database to provide all of that like this:
That's way more information than is required and so it takes longer to retrieve. What you really want to request is something like this:
So double check your database table calls are only requesting what is needed for that page content to be rendered.
Pagination is where you break lists down so you only dispay, for example, 20 products per page even though you have 100 products available. Everyone with long lists uses it - just look at Google's search results! Pagination.
Again with pagination, if you do it right, you are only requesting say 20 records from a database table, not all 100. That brings the time for a request to be processed right down.
If you've scrubbed up your PHP so that its so clean it shines but you're still seeing slow code execution the chances are that its not the code, its the server. You can have great PHP but if its being executed on a slow server its going to grind along.
This can be really common with websites on shared hosting. Their sharing a server with other websites and when they get really busy the whole server slows to a snails pace with terrible effects on your page loading speeds.
Even for smaller websites Virtual Private Servers (VPS) aren't a major investment and those with Solid State Drives (SSDs) rather than Hard Disk Drives (HDD) can make a real difference.
Any decent hosting company will let you take their servers for a spin by offering monthly contracts so you only have to pay for 30 days and if its not up to scratch you can walk away. Buy a couple of cheap domain names and upload your sites to alternative servers so you can do some like for like comparisons.
Remember when comparing to run tests several times and keep a track of the results so you can see the averages. Run the tests at different times of the day to see if their servers experience issues at particular times like the height of the business day or early evenings.
Don't worry too much about duplicate content issues. Your only doing this for a day and if Google were to chance upon your tests it would ding those cheap domains which you are not going to use anyway.
Search engine optimizing PHP is really about improving the execution time of the code so you can bring down your page loading times. However there is usually a whole lot of other stuff you can do to improve page loading speed significantly before you get to PHP.
And if cleaning up your PHP doesn't seem to make any noticeable difference consider the hardware, in other words the hosting server, as the guilty part that needs to be changed.
I'm Tim Hill, a Search Engine Optimization and Online Marketing specialist. I created this site to help others understand that SEO is not a mysterious black art!.
If your a newbie try the Getting Started in SEO page, otherwise feel free to dig around and learn more.