Jay GajjarSenior Software Engineer

Laravel and PHP development

Laravel performance optimization for slow apps and heavy databases

Laravel performance optimization, the way I do it, starts by measuring where the time goes and then fixing the queries, indexes, caching and background work behind it. Most slow Laravel apps are not slow because of PHP. They are slow because one page runs hundreds of queries, a report scans millions of rows, or an email is sent while the user waits.

ContactHire on Fiverr (opens in a new tab)Available for new projects. I reply within an hour during working hours.

What’s included

  • Profiling of slow pages, API endpoints and jobs with Debugbar, Telescope or Pulse and the MySQL slow query log
  • Laravel query optimization: N+1 fixes, eager loading, narrower selects, and counts and sums done in SQL
  • Index design from EXPLAIN plans: composite and covering indexes with the columns in the right order
  • Redis caching for expensive reads, with clear invalidation rules, plus config, route and view caching
  • Moving slow work to queues: emails, PDFs, imports, exports and third-party API calls
  • Large-table strategies: chunked processing, cursor pagination, archiving and MySQL partitioning
  • PHP and server tuning: OPcache, PHP-FPM worker counts, an optimized Composer autoloader, session and cache drivers
  • A before-and-after report with timings for every page, query and job I changed

What Laravel performance optimization covers, and what it does not

This service is about the server side of a Laravel or PHP application: how long the app takes to build a response, how hard it works the database, and how it behaves as data and traffic grow. The symptoms are a high time to first byte, a dashboard that takes ten seconds to open, reports that time out, API calls that a mobile app gives up on, or a server whose CPU sits at full load every month end.

It is not front-end speed work. If your problem is heavy images, render-blocking scripts and Core Web Vitals on a content site, that is a different job, covered on my WordPress speed optimization page. A fast front end cannot hide a six-second database query, and a fast backend cannot fix an oversized hero image. Often both matter, and I will tell you which one is costing you more.

Why Laravel apps get slow: the usual causes

The causes repeat from app to app. Eloquent makes it easy to write code that is correct on test data and slow on real data, and the slowdown arrives gradually, so nobody notices the week it started.

  • N+1 queries. A list of 50 orders that loads each customer separately runs 51 queries. Eager loading with with() makes it two. Model::preventLazyLoading() in development catches new ones before they ship.
  • Missing or misordered indexes. An index on status does not help a query filtering on company_id and a date range. Column order in a composite index matters, and wrapping a column in a function (whereDate() compiles to DATE(created_at)) stops MySQL using the index at all.
  • Loading too much. Model::all() on a two-million-row table, or get() followed by a count in PHP, instead of chunkById(), lazy() or a SQL aggregate.
  • Deep offset pagination. Page 5,000 of a list makes MySQL read and throw away every row before it. Cursor pagination stays quick at any depth.
  • Work done inside the request. Sending mail, building PDFs or calling a slow external API while the user waits, instead of in a queued job.
  • Leading wildcards. LIKE '%term%' cannot use a normal index; a FULLTEXT index or a dedicated search tool can.
  • Untuned production settings. APP_DEBUG left on, no config or route cache, OPcache disabled, file sessions on a busy server.

How I approach Laravel query optimization and performance tuning

I measure first and change second. On a copy of production data, or a realistic volume of seeded data, I record response times, query counts and memory use, then read the EXPLAIN plan for each slow query. EXPLAIN ANALYZE in MySQL 8 shows where the rows and the time actually go, which is often not where the code suggests.

Then I fix in order of payoff. Query and index changes usually come first because they are cheap and low risk. Caching comes second, and only with a clear rule for when each cache is cleared, because a fast page showing yesterday's balance is a bug, not a gain. Queues and structural changes such as partitioning come last, because they change how the system runs day to day.

Laravel performance tuning must not change behavior. Every change is checked against the same results as before, and anything involving money, stock or document numbering keeps its transactions and row locks exactly as they were.

Large tables, queues and partitioning: lessons from production

On a brokerage risk platform where I was a core developer, report tables gained rows every day across more than 1,000 trading accounts, and deleting history was not an option. The largest tables are partitioned by week, and a scheduled job adds the next partition automatically, so a report reads only the weeks it needs. The trade-off is honest: partition maintenance becomes a job that must never be missed, so it is watched.

On the same platform, data arrives from external trading systems on their own schedules, so ingestion runs in scheduled and queued jobs rather than in web requests. That pattern (accept quickly, process in the background, make each job safe to retry) is what keeps response times flat as volume grows. Uploads follow the same thinking: on an export operations ERP, large order batches are imported in batches instead of in one long request that times out halfway.

Why hire me for Laravel speed optimization

You work directly with the developer who profiles and changes the code. I write Laravel and MySQL every day, including queues, transactions and row-level locking, so I can tell a slow query from a slow design and fix the right one. I am based in India and work remotely with clients in different time zones; we agree on update times at the start.

I also explain what I find. You get the numbers before and after, the reason for each change, and a short list of what to watch as data grows, so your own team can keep the app quick. If you want to check the basics yourself first, my Laravel performance checklist is a free starting point.

What affects the cost of Laravel performance optimization services

Cost depends on how many slow areas there are, the size of the data, whether I can test against a production-sized copy of the database, whether automated tests exist to confirm nothing changed, and whether server tuning is in scope. One slow report is a small job; an app that slows down everywhere under load is a larger one.

I usually start with a short audit: a profile of your slowest pages and jobs and a prioritized list of fixes with the expected effect of each. You then get a fixed quote for the fixes after a short call or written brief. A hosting upgrade is the last resort, not the first, because more CPU rarely makes up for a missing index.

How the work runs

  1. Baseline

    We agree the pages, endpoints and jobs that matter. I record their response times, query counts and memory use, and pull the slow query log from production.

  2. Diagnose

    I read EXPLAIN plans, trace N+1 patterns with Debugbar or Telescope, and check server settings such as OPcache, PHP-FPM workers and the cache and session drivers.

  3. Fix by payoff

    The cheapest high-impact fixes ship first: eager loading, indexes, narrower selects, aggregates in SQL. Caching and queues follow where they make sense.

  4. Verify

    The same pages are measured again on the same data, and results are compared with the originals. Index changes on large tables are applied at a quiet time so they do not hold up writes.

  5. Report and guard

    You get the before-and-after numbers, plus guards such as preventLazyLoading in development and slow-query logging, so new code does not quietly undo the work.

Tools and technologies

  • Laravel 10 to 13
  • PHP 8.2 to 8.5
  • MySQL 8
  • Redis
  • Laravel Horizon
  • Laravel Telescope
  • Laravel Debugbar
  • Laravel Pulse
  • Laravel Octane
  • OPcache
  • PHP-FPM
  • Nginx
  • Supervisor

Proof from real projects

Questions

  • Why is my Laravel app slow?

    Usually because of the database rather than PHP: N+1 queries, missing indexes, or loading far more rows than a page needs. The next most common causes are slow work done during the request (mail, PDFs, external API calls) and production settings such as debug mode left on. Profiling shows which one applies, usually within the first few hours.

  • How does caching help Laravel performance?

    Caching stores the result of expensive work, such as a dashboard query, so the next request reads it from Redis instead of rebuilding it. It helps most for data that is read often and changes rarely. The hard part is invalidation, so I define exactly when each cache is cleared rather than caching everything for an hour and hoping.

  • How does database indexing speed up a Laravel app?

    An index lets MySQL jump to the matching rows instead of reading the whole table. The right index depends on the exact filters and sort order of your slow queries, which is why I design them from EXPLAIN plans rather than adding one to every column. Too many indexes slow down inserts, so each one has to earn its place.

  • Do you use Laravel Octane?

    Sometimes, but rarely first. Octane keeps the app in memory between requests (with FrankenPHP, Swoole or RoadRunner), which cuts framework boot time, but it does nothing for a slow query and it needs code that does not leak state between requests. I fix the database and request work first, then consider Octane if boot time is still a real share of the response.

  • Will optimization change how my app behaves?

    It should not, and I check that it does not. Every change is compared against the previous results on the same data, and the transactions and locks around money, stock or numbering stay as they are.

  • Do I just need better hosting?

    Rarely as the first step. A bigger server makes a missing index slightly less painful while the table keeps growing. If profiling shows the code is efficient and the server is genuinely at its limit, I will say so and suggest the smallest upgrade that fits.

  • How is this different from WordPress speed optimization?

    This service is server-side work inside your Laravel application: queries, indexes, queues and caching. WordPress speed work is mostly front-end and plugin work aimed at Core Web Vitals. The biggest wins in business apps are usually in the database, so that is where this work starts.

  • Can you keep the app fast after the project ends?

    Yes, either by handing your team the guards and a checklist, or as part of Laravel maintenance and support, where I review slow-query logs and failed jobs every month.

Further reading

Tell me what you are building.

A few lines about the project, who will use it and when it needs to ship are enough to start. You get a straight answer on whether laravel performance optimization is the right fit, and what it would take.

Status
Available for new projects
Reply time
I reply within an hour during working hours.
Working hours
9 AM to 9 PM IST (UTC+5:30)
Languages
English, Hindi, Gujarati

How pricing, payments and terms work

Prefer email? Write to jaygajjar.dev@gmail.com.