php - Laravel instantiating $response takes abnormally long

I have a Laravel 5.8 application, with very long loading times. Laravel??�s speed is debugable within the file. Which I have tried like this:

{-code-2} 

Between {-code-3} being set, and the response being sent, it will take a staggering six to fourteen seconds to load. Switching my code to:

{-code-5} = $app->make(Illuminate\Contracts\Http\Kernel::class);

dd(microtime(true) - {-code-3});    

$response = {-code-5}->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

Will yield an average loading time of about 0.6 to 2 seconds between Laravel booting and {-code-5} being set. This means that loading the kernel takes an average of 1.2 seconds, and processing the request takes about 11-13 seconds. Now, what I have tried to speed up the fetching of a page so far:

Dumping cache

Most Laravel problems are usually solved by clearing the cache, running {-code-6}, dumping {-code-7}, etc. This didn't yield any time difference.

Reinstalling the project

I tried to reinstall the project from it's GitHub repository, which also had no impact on the loading times. I rebuild the docker container from scratch as well, more about docker in the next paragraph

Docker

As I have been doing a lot of research into why my Laravel application could be slow, I stumbled upon many articles stating that docker could slow down Laravel substantially. To combat this, I??�ve tried the following:

PHP artisan serve, instead of using docker, I??�ve tried to use the built in webserver. This does not speed up the application.

  • I switched between a few PHP 7.X versions, to no avail.
  • My other projects work fine with the artisan serve command. Loading times are somewhere around 20-200 milliseconds.

Xampp, does not speed up the executable time.

  • My other projects work fine with xampp. Loading times are around 20-300 milliseconds.

Controller debugging

As I have eliminated the possibility of my webserver being the bottleneck, I timed the difference between the first and last line of my controller like this:

{-code-8}

This yields the following results:

{-code-9}

While these seem like respectable times, my application didn??�t take the average time of 0.22 seconds to boot, but rather took the expected eight to twenty seconds to boot. I tried it once again, now with a fully empty controller like this:

{-code-10}

Which yields an average controller execute time of 0.0 seconds. While remaining as slow as before.

Middleware

My next thought would be to debug the {-code-11} my project uses. As it is an enterprise application, there is a lot of validation going on under the hood, which is run before every request gets to a controller. I started off by completely removing all {-code-11} from the {-code-12} file. Rerunning my application does not yield any time difference. With no {-code-13} being run, I can conclude that my slow loading times aren't due to a unoptimized {-code-13}.

Service providers

Just like the {-code-13}, {-code-14} run on every request. Removing all non-essential {-code-14} in {-code-15} yields no loading time difference.

Where to go from here?

My {-code-12} now looks like:

<?php

use Illuminate\Support\Facades\Route;
/*
|

Answer

Answer

Answer

Answer

Answer

Answer

Answer

---- | Web Routes |

Answer

Answer

Answer

Answer

Answer

Answer

Answer

---- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/greeting', function () { return 'Hello World'; });

It still takes 12 seconds to load. It seems as though something is slowing down:

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

Yet, removing practically the entire project has close to zero effect on the projects speed. How can I speed up this essential project?

Answer

Answer

Answer

Answer

Answer

Answer

Answer

---- | Web Routes |

Answer

Answer

Answer

Answer

Answer

Answer

Answer

---- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/greeting', function () { return 'Hello World'; });|||$response = $kernel->handle( $request = Illuminate\Http\Request::capture() );

Source