Daniel Kisantal Legacy PHP modernization

PHP performance optimization

Slow pages, timeouts under load, a server bill that keeps growing. I measure where the time actually goes, fix the biggest causes first, and show the numbers before and after.

Measure first

Guessing is how teams spend weeks optimizing code that was never the problem. I start with a profile of real requests, using Blackfire, Xdebug's profiler or SPX, plus the database's slow query log, and rank the findings by time saved.

What usually makes legacy PHP slow

  • N+1 queries: a list page that runs one query per row, hundreds per request.
  • Missing or wrong indexes: found with EXPLAIN on the slowest queries, often the single biggest win.
  • OPcache off or undersized: PHP recompiling every file on every request.
  • Composer autoloading without an optimized classmap in production.
  • No caching of expensive results, configuration or rendered fragments, so the same work runs on every request.
  • Sessions and file locks that make parallel requests from one user wait for each other.
  • PHP-FPM settings that do not match the server: too few workers queue requests, too many run out of memory.
  • Heavy work inside the request: emails, PDF generation or API calls that belong in a background queue.

How the work goes

  1. Baseline: response times and throughput of the important pages, measured the same way before and after.
  2. Profile and rank: where the time goes, and what each fix is worth.
  3. Fix in order of impact, each change small and deployable on its own.
  4. Report: the before and after numbers, and what to watch so the app stays fast.

On one engagement for a privacy and compliance startup I profiled a production service and removed its bottlenecks this way. Performance work often comes with a PHP 8 upgrade, since PHP 8 itself is faster than PHP 5 and 7.

Ask about a slow application

Questions

Will upgrading to PHP 8 alone make the app faster?

Often noticeably, especially coming from PHP 5. But in most slow legacy applications the biggest cost is the database: N+1 queries, missing indexes and work repeated on every request. Those need fixing in the code, whatever the PHP version.

Do you need access to production?

Read-only access to metrics or logs helps, and profiling can run safely on production with low overhead tools. If that is not possible, I reproduce the load on a staging copy with realistic data.

Does the JIT in PHP 8 help web applications?

Rarely by much. Typical web requests wait on I/O and the database, where the JIT does nothing. OPcache, preloading and fixing queries matter far more.