Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
  1. Home
  2. Blog
  3. Why the Application Is Slow
PHP Development

Why the Application Is Slow

Why PHP applications are slow: too many queries, missing indexes and over-fetching data, finding them before fixing anything, and why caching comes last.

Updated 2 min readBy SpiderHunts Technologies

Free estimateNo obligation

Get a free estimate

Tell us what you need. A senior engineer reads every enquiry.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →

Quick answer — TL;DR

It is almost always the queries: too many of them, missing indexes, or fetching far more data than is used. Measure before optimising anything else.

It is the database, not PHP

When a business application is slow, PHP execution time is rarely the cause. The time is spent waiting for database queries, and usually for far more of them than anyone realised.

We have seen a single page issuing four hundred queries because a loop fetched related records one at a time. No amount of PHP optimisation fixes that.

The three usual causes

  1. Query multiplication — one query per row in a loop, instead of one query total
  2. Missing indexes on columns used for filtering or joining
  3. Over-fetching — selecting everything when three columns are needed

Find them before fixing them

  • Log query count and total time per request
  • Identify the slowest pages by real user timing, not by impression
  • Look at the query log for repeated similar queries
  • Use the database's own explain facility on the slow ones

Optimising without measuring produces a lot of work on the wrong queries, which is the most common way performance projects waste money.

Indexes are usually the quick win

A missing index on a foreign key or a frequently filtered column can turn a query from milliseconds into seconds. Adding it is a one-line change with an immediate effect.

Index the columns you filter, join and sort by. Do not index everything — each index costs on writes.

Caching comes after

Do firstThen consider
Fix query multiplicationQuery result caching
Add missing indexesObject caching
Fetch only needed columnsFull page caching
Paginate large resultsA read replica

Caching a badly-written query hides the problem rather than solving it, and the problem reappears the moment the cache misses.

FAQ

Frequently asked questions

The questions readers ask us after this guide.

Still have a question?

Ask us directly — a senior engineer will get back to you.

Ask about your project

How many queries should a page make?

Usually under twenty for a typical business page. Hundreds indicates query multiplication in a loop.

Will more server resources fix it?

Temporarily and expensively. A query problem scales with data volume, so hardware buys time rather than a solution.

How do we find missing indexes?

The database's slow query log plus its explain output. Both are free and both point directly at the problem.

Is an ORM the cause?

Not inherently — lazy loading in loops is, and that is usually avoidable by loading relations explicitly.

Keep reading

More on PHP Development

PHP Development

Why PHP Is Still a Sensible Choice

Is PHP still a good choice for business applications? Where modern, typed PHP fits, where another language is better, and the hosting and hiring arguments.

PHP Development

Improving Old Code Without a Rewrite

Modernising a legacy PHP application without a rewrite: move to a supported PHP version, add tests around what matters, then strangle rather than replace.

Start here

Application slow and getting slower?

Count the queries on your slowest page first. It is usually the whole answer.

  1. You tell us what you needTwo minutes on the form, or a message on WhatsApp.
  2. A senior engineer reviews itAnd comes back with questions, a realistic range and an honest view on fit.
  3. Free 30-minute scoping callWe talk through scope, options and a realistic estimate — with no obligation.
Free estimateNo obligation

Talk to someone who builds this

Send a short brief and we will come back with an honest view and a realistic range.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →