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.
Xampp, does not speed up the executable time.
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;
/*
|
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?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.