dulan
dulan

Reputation: 1604

Laravel optimization

So I've heard, because Laravel is easy to develop, it loads a whole bunch of dependancies which may or may not be needed. I want to optimize Laravel for the sake of better performance, and I wonder if there's any plugins I could utilize so as to find out and remove unwanted Laravel classes/services to suit exactly my own needs?

Upvotes: 1

Views: 2578

Answers (7)

Zakro Gogolidze
Zakro Gogolidze

Reputation: 39

Autoloader Optimization: When deploying to production, make sure that you are optimizing Composer's class autoloader map so Composer can quickly find the proper file to load for a given class:

composer install --optimize-autoloader --no-dev

Optimizing Configuration Loading: When deploying your application to production, you should make sure that you run the config:cache Artisan command during your deployment process:

php artisan config:cache

This command will combine all of Laravel's configuration files into a single, cached file, which greatly reduces the number of trips the framework must make to the filesystem when loading your configuration values.

Optimizing Route Loading: If you are building a large application with many routes, you should make sure that you are running the route:cache Artisan command during your deployment process:

php artisan route:cache

This command reduces all of your route registrations into a single method call within a cached file, improving the performance of route registration when registering hundreds of routes.

Server Configuration: Nginx If you are deploying your application to a server that is running Nginx, you may use the following configuration file as a starting point for configuring your web server. Most likely, this file will need to be customized depending on your server's configuration. If you would like assistance in managing your server, consider using a service such as Laravel Forge:

  server {
    listen 80;
    server_name example.com;
    root /example.com/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Upvotes: 0

Altair Cp
Altair Cp

Reputation: 1

I use the following commands for laravel 5:

php artisan optimize --force -n

php artisan config:cache

php artisan route:cache

Also make user to use production env.

You can also disable/comment out providers and alias from config/app.php that are not being used

Upvotes: 0

Tony
Tony

Reputation: 71

The latest version of Laravel, soon to be released and it will gets rid of all of the unnecessary elements and has a vast improvement. I would suggest using this upcoming version rather than trying to streamline the current version, they have done it all for you.

Upvotes: 5

Alexandru Muresan
Alexandru Muresan

Reputation: 115

Take a look at Lumen and compare the dependencies, it is basically a slim version of Laravel.

Besides the dependencies you will also notice it uses $app->get() instead of Route::get() which will be faster if you have a lot of routes

Upvotes: 0

Nuruzzaman Milon
Nuruzzaman Milon

Reputation: 312

use these commands in terminal-

composer dump-autoload -o
php artisan optimize

-o flag create the optimized autoload file.

Upvotes: 2

cherrysoft
cherrysoft

Reputation: 1195

You can use Lumen which is an amazing Microframework by Laravel.

Upvotes: 1

Amrit G.C
Amrit G.C

Reputation: 46

if you are on debuging mode :: on you laravel project directory

run

php artisan optimize --force

else

run

php artisan optimize on you project folder

(It will optimize Laravel Framework for Better Performance as much as possible)

Upvotes: 0

Related Questions