Performance optimization in PHP is one of those topics where 90% of articles repeat the same surface-level advice. After working on real production systems handling 10K+ concurrent users, I've learned which optimizations actually matter.
1. Use OPcache — But Configure It Properly
OPcache is enabled by default in PHP 7+, but the default configuration leaves a lot of performance on the table. Set opcache.memory_consumption=256, opcache.max_accelerated_files=20000, and always set opcache.validate_timestamps=0 in production.
2. Eager Load Relationships in Laravel
The N+1 query problem kills more apps than anything else. Use with() religiously. Use Laravel Telescope or Debugbar to spot these in development before they hit production.
3. Index Your Database Properly
A query that takes 2 seconds on a table with 100K rows will take 20 seconds with 1M rows without proper indexes. Index every foreign key, every column used in WHERE clauses, and every column used in ORDER BY.
4. Cache Aggressively
Laravel's cache system with Redis is one of the most underutilized tools. Cache database-heavy queries that don't change often. A site-settings query that runs on every page load should be cached indefinitely and busted on update.
5. Use Queue Workers for Heavy Tasks
Sending emails, generating PDFs, processing images — none of these should block the HTTP response. Push them to a queue and let a worker handle them asynchronously.
6. Optimize Autoloading
Run composer dump-autoload --optimize in production. This generates a single class map instead of traversing the filesystem on every request.
7. Profile Before Optimizing
The biggest mistake developers make is optimizing things that aren't the bottleneck. Use Blackfire, Xdebug, or even simple timing logs to find the actual slow parts before touching code.
Performance is a feature. Build it in from the start, not as an afterthought.