Performance has always been a point of Laravel framework, so tuning the Laravel program is a must-learn skill. Next, share some of the best practice www.itxdl.cn and tuning tips, and you'll also be welcome to comment on other suggestions. Here is a simple list: Configure information cache artisan Config:cache route cache artisan Route:cache class map load optimization artisan optimize auto load optimization composer Dumpautoload Use Memcached to store sessions config/session.php use professional cache drives config/cache.php database request optimization to write cache logic for datasets using the Instant compiler (JIT), such as: HHVM, Opcache front-end resource and Elixir 1. The configuration information cache uses the following Artisan commands to merge all configuration information from the Config folder into a single file, reducing the number of files loaded at run time: Php Artisan config:cache The above command generates a file bootstrap/cache/c onfig.php, you can use the following command to cancel the configuration information cache: PHP artisan config:clear This command does is to delete the bootstrap/cache/config.php file. Note: The configuration information cache is not automatically overloaded with updates, so it is recommended that you turn off the configuration information cache during development, which is typically used in a production environment and can be used with the Envoy task runner. 2. Route cache routing cache can effectively improve the efficiency of the router registration, in large applications, the more obvious, you can use the following command: PHP artisan route:cache above command will generate bootstrap/cache/routes.php file, you need to note The route cache does not support routing anonymous function authoring logic. You can use the following command to clear the route cache: PHP artisan route:clear This command does is to delete the bootstrap/cache/routes.php file. Note: Routing caches are not automatically overloaded with updates, so it is advisable to turn off the route cache during development, which is typically used in production environments and can be used with the Envoy task runner. 3. Class-Map load optimization The optimize command merges commonly loaded classes into a single file,Reduce file loading to improve operational efficiency: PHP artisan optimize--force generates bootstrap/cache/compiled.php and Bootstrap/cache/services.json two files. You can add classes to be merged by modifying the config/compile.php file. In the production environment, the parameter--force does not need to be specified, and the file is generated automatically. To clear the class-map load optimization, run the following command: PHP artisan clear-compiled This command deletes the two files generated above optimize. Note: This command runs after PHP artisan config:cache because the optimize command generates files based on configuration information such as providers array of config/app.php files. 4. Automatic load Optimization This command is not only for Laravel programs, but for all programs built using composer. This command converts PSR-0 and PSR-4 to a class-map table to increase the load speed of the class. Composer Dumpautoload-o Note: This is already done in PHP artisan optimize--force command. 5. Use Memcached to store each Laravel request, will produce a session, modify the memory of the session can effectively improve the program efficiency, session configuration information is config/session.php, proposed to modify the Memcached or Redis and other professional Cache software: ' Driver ' = ' memcached ', 6. Using Professional cache Drive "Cache" is one of the magic weapons to improve the efficiency of the application, the default cache driver is the file cache, it is recommended to switch to a professional caching system, such as Redis or Memcached, and it is not recommended to use the database cache. ' Default ' = ' Redis ', 7. Database request optimization data correlation model reads using lazy preload and preload; Use Laravel Debugbar or clockwork to pay attention to the total number of database requests per page; This space is only relevant to Laravel, other information about data optimization, please consult other materials. 8. Logical use of the cache logic for data set writingAravel provides caching layer operations, the data collection from the database to cache, reduce the pressure on the database, running in-memory professional cache software to read data is much faster than the database. $posts = Cache::remember (' index.posts ', $minutes = +, function () {return Post::with (' comments ', ' tags ', ' author ', ' SEO ')->wherehidden (0)->get (); }); Remember even the data correlation model has been cached, how convenient it is. 9. Using the instant compiler HHVM and Opcache can easily let your application without any modification, directly improve the performance of 50% or higher, phphub before doing an experiment, see: Using Opcache to improve the performance of PHP 5.5+ program. 10. Front-end resource consolidation as the standard of optimization, a page should only load a CSS and a JS file, and the file to facilitate the CDN, need to change the file name with the changes. A skill to optimize PHP program Laravel 5 Framework performance has always been the Laravel framework is a criticism of the point, so tuning Laravel program is a must learn skills. Next share some of the best practices for development, as well as tuning tips, and you are welcome to comment on other suggestions. Here is a simple list: Configure information cache artisan Config:cache route cache artisan Route:cache class map load optimization artisan optimize auto load optimization composer Dumpautoload Use Memcached to store sessions config/session.php use professional cache drives config/cache.php database request optimization to write cache logic for datasets using the Instant compiler (JIT), such as: HHVM, Opcache front-end resource and Elixir
|