Score:0

Why is my Laravel App having 3+ seconds TTFB in Production?

cn flag

I've looked around but can't find a definitive answer on if things like Images affect TTFB which would be my best guess as to why my site is taking so long to load in production. After the page is completely done being received, I see it's transferred 40.7 mb resources which is a lot but the initial page load accounts for only 20.1kb of that, followed by images/js/css.

The .har file exported from the Network inspector:

"pages": [
  {
    "startedDateTime": "2022-04-01T23:10:26.010Z",
    "id": "page_1",
    "title": "https://example.com/",
    "pageTimings": {
      "onContentLoad": 5878.881000004185,
      "onLoad": 6390.734000000521
    }
  }
],

And after this follows things such as images/js/css.

Things I tried:

  • Replacing the content in index.php with a simple echo statement which was <?php echo 'foobar'; ?> and this resolved the issue immediately as the page took less than a second to load.
  • Ensured that it had the same configuration for the cache as other applications hosted on the same server and which also take much less time to load.
  • composer install --optimize-autoloader --no-dev
  • composer dump-autoload -o
  • php artisan route:cache
  • php artisan config:cache

My Question is: although resources such as images/css/js have their own TTFB could they be increasing the time to first byte for the initial page?

Edit: Another thing I wanted to point out was that this occurs on pages that are not resource intensive and also that the server it's on is Microsoft Windows Server 2016 Standard and VMware, Inc. VMware7.1

Score:0
tz flag

Why is my Laravel App having 3+ seconds TTFB in Production?

Profile your code. Use xdebug then pipe it to your IDE or to KCacheGrind/QCacheGrind to see what's burdening your code.

although resources such as images/css/js have their own TTFB could they be increasing the time to first byte for the initial page?

Not on their own, depends on your server load and your configurations.

Again, try profiling your code first. Preferably not in production.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.