php Laravel 工匠优化最佳实践
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31895854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel artisan optimize Best Practices
提问by suncoastkid
I'm trying to fully understand the Laravel (5.1) artisan optimize
command and best practices, but the documentation seems lacking. I don't have Composer installed on the production server so, specifically, I want to know what files are modified or created when running artisan optimize --force
on development that must get pushed to production. The goal being not to blow up the app in production! After running the command, I see the following files have been modified:
我试图完全理解 Laravel (5.1)artisan optimize
命令和最佳实践,但文档似乎缺乏。我没有在生产服务器上安装 Composer,所以,特别是,我想知道artisan optimize --force
在开发中运行时修改或创建了哪些文件必须推送到生产。目标是不要在生产中炸毁应用程序!运行该命令后,我看到以下文件已被修改:
\bootstrap\cache\compiled.php
\vendor\composer\ - the entire directory
\vendor\autoload.php
Am I overthinking this, or do I just push these files to production and I'm good to go? Also, what is the best practice regarding when to run artisan optimize
? Each time a new model is created? What about controllers, routes and helper classes?
我是不是想得太多了,还是我只是将这些文件推送到生产环境,然后我就可以开始了?另外,关于何时运行的最佳实践是什么artisan optimize
?每次创建一个新模型?控制器、路由和辅助类呢?
Lastly, I see the \bootstrap\cache\compiled.php
file is a whopping 548KB and almost 17K lines! Is that really considered optimal?
最后,我看到\bootstrap\cache\compiled.php
文件高达 548KB,几乎有 17K 行!这真的被认为是最佳的吗?
采纳答案by Ben Claar
[edit - As @crishoj says, as of Laravel 5.5, php artisan optimize is no longer needed]
[编辑 - 正如@crishoj 所说,从 Laravel 5.5 开始,不再需要 php artisan optimize]
Normal Laravel practice isto have composer installed on your production server.
正常的 Laravel 实践是在您的生产服务器上安装 composer。
These are the steps Envoyer(made by Laravel's creator) takes to deploy an app on production -- I've annotated them below:
这些是Envoyer(由 Laravel 的创建者制作)在生产环境中部署应用程序所采取的步骤——我在下面对它们进行了注释:
# Install application dependencies, such as the Laravel framework itself.
#
# If you run composer update in development and commit the `composer.lock`
# file to your repository, then `composer install` will install the exact
# same versions in production.
composer install --no-interaction
# Clear the old boostrap/cache/compiled.php
php artisan clear-compiled
# Recreate boostrap/cache/compiled.php
php artisan optimize
# Migrate any database changes
php artisan migrate
回答by crishoj
As of Laravel 5.5, php artisan optimize
is not longer required.
从Laravel 5.5 开始,php artisan optimize
不再需要。
回答by Iman Ghafoori
You can also take benefit of laravel packages to easily optimize your application by caching page partials
您还可以利用 laravel 包通过缓存页面部分来轻松优化您的应用程序