DEV Community

Cover image for WordPress Performance & Digging into PHP
lizziekardon
lizziekardon

Posted on • Originally published at pagely.com

WordPress Performance & Digging into PHP

OPTIMIZING YOUR PHP CODE FOR HIGHER PERFORMANCE
In general, optimizing your PHP code for higher performance fits into two categories:

  • Running less code
  • Making fewer calls to external resources.

RUNNING LESS CODE

Running less code is done in both the obvious way; turning off plugins where the feature adds little value and, the less obvious way; transient caching and code optimization.

Transient caching is pretty straight forward:

  • Find a section of code that takes a lot of time to produce some HTML.
  • Figure out if it’s personalized, or can be cached globally or as some group of variants.
  • Use the WordPress Transients API to cache that HTML.

A tool like New Relic can help you identify slow chunks of code, so you can make those fixes efficiently.

Transient caching can also be used for datasets instead of just HTML but, in general, the closer to final output that you can do caching, the more impact you will have.

Code optimization is harder, which is where you likely need a developer to dig into things. It might be as simple as switching to a more efficient algorithm, but often it will take a larger rethink and rework of how things are being done.

MAKING FEWER EXTERNAL CALLS

When you make a MySQL query or an http request to an API like Twitter, PHP sits and waits for the response.

You want to do less of this.

The Transients API can be the answer here, caching the data from API calls where it doesn’t need to be fresh. On the database side, you might be able to fetch less data from smart page design.

Does a page really need to show content from 100 posts at once? Probably not.

TL;DR
Huge wins are possible, but look for easy wins from transient caching and design first.

When it comes to your site’s performance, and how PHP effects that, it’s all about being smart. Understand what’s needed in terms of PHP worker counts vs CPU cores, and how to use your resources efficiently without extra code hanging around to slow things down.

If it’s over your head, talk to a managed WordPress host that can help alleviate the pressure and get things running smoothly.

Read the whole post at https://pagely.com/blog/wordpress-performance-php/

Top comments (0)