Laravel artisan 优化最佳实践

Laravel artisan optimize Best Practices

我试图完全理解 Laravel (5.1) artisan optimize 命令和最佳实践,但似乎缺少文档。我没有在生产服务器上安装 Composer,所以,具体来说,我想知道在 运行 宁 artisan optimize --force 开发时修改或创建了哪些必须推送到生产的文件。目标是不要在生产中炸毁应用程序! 运行执行命令后,我看到以下文件已被修改:

\bootstrap\cache\compiled.php
\vendor\composer\ - the entire directory
\vendor\autoload.php

我是想多了,还是只是将这些文件推送到生产环境就可以了?此外,关于何时 运行 artisan optimize 的最佳做法是什么?每次创建一个新模型?控制器、路由和助手 类 呢?

最后,我看到 \bootstrap\cache\compiled.php 文件高达 548KB,几乎有 17K 行!这真的被认为是最佳的吗?

[编辑 - 正如@crishoj 所说,从 Laravel 5.5 开始,不再需要 php artisan 优化]

正常Laravel实践在您的生产服务器上安装作曲家。

这些是 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

Laravel 5.5 开始,不再需要 php artisan optimize

您还可以利用 laravel 包通过缓存页面部分轻松优化您的应用程序

https://github.com/imanghafoori1/laravel-widgetize