Laravel 5 framework performance optimization skills, laravel Performance Optimization

Source: Internet
Author: User

Laravel 5 framework performance optimization skills, laravel Performance Optimization

Performance has always been a criticism of the Laravel framework, so tuning Laravel programs is a required skill.

Next, I will share some development best practices and optimization skills. If you have other suggestions, please leave a message to discuss them.

1. Configure Cache Information

Use the artisan Command provided by laravel to cache all configurations in the config file to a file.

php artisan config:cache

All cache information is stored in the bootstrap/cache/config. php file. You can also use the following command to delete the cache information:

php artisan config:clear

When the configuration information is modified, you can directly execute php artisan config: cache, because it will automatically execute php artisan config: clear first, and then execute php artisan config: cache.

 

2. Route information Cache

When there are more and more routes, especially in large projects, the routing cache effect is obvious.

php artisan route:cache

All the routes will be cached in the bootstrap/cache/routes. php file. If you want to use the route cache, then all the routes cannot use the closure, that is, the form of an anonymous function. You can also use

php artisan route:clear

Clear the route cache.

 

3. Class ing loading Optimization

The optimize command caches some common classes to files. By reducing file loading, the performance is improved:

php artisan optimize --force

The bootstrap/cache/packages. php and bootstrap/cache/services. php files are generated.

In the production environment, the parameter -- force does not need to be specified, and the file is automatically generated.

To clear the class ing loading optimization, run the following command:

php artisan clear-compiled

This command will delete the two files generated by optimize.

Note: This command runs after php artisan config: cache, because the optimize command is based on the configuration information (for example:config/app.phpFileprovidersArray) to generate files.

 

4. Use redis/memcached to store session

Each laravel request generates session information. By default, the file storage method is used. It is stored in the storage/framework/sessions file and can be modified in config/session. php.

'driver' => 'redis',

 

5. Use a professional cache drive

"Cache" is a magic weapon to improve the efficiency of application programs. The default cache driver isfileFile caching. We recommend that you switch to a professional cache system, such as Redis or Memcached. We do not recommend that you use database caching.

You can modify the configuration file config/cache. php:

'default' => 'reids',

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.