php - Laravel - 延迟服务提供者如何工作?

标签 php laravel laravel-5

官方文档说:

If you open the config/app.php file included with Laravel, you will see a providers array. These are all of the service provider classes that will be loaded for your application. Of course, many of these are "deferred" providers, meaning they will not be loaded on every request, but only when the services they provide are actually needed.

If your provider is only registering bindings in the service container, you may choose to defer its registration until one of the registered bindings is actually needed. Deferring the loading of such a provider will improve the performance of your application, since it is not loaded from the filesystem on every request.

我如何知道某个包是否使用了不会在每次请求时都加载的“延迟”服务提供者?

如果没有设置 defer 属性,默认值是什么?

...在 bootstrap/cache/services.php 的缓存 list 中,providers、eager、deferred 和 when 之间有什么区别?

那么,如何知道一个包对于整个应用程序来说是否过重?

例如,我想使用非常简单的“cviebrock/eloquent-sluggable”包,并使用 trait 在模型中添加功能。 而且还实现了一项服务,该服务提供了将在观察者中使用的绑定(bind),我如何知道它是否仅在我保存或编辑模型时加载?

谢谢。

最佳答案

If the defer property is not set, what default value is implied?

protected $defer 的默认值为 false

...and in the cached manifest at bootstrap/cache/services.php what is the difference between providers, eager, deferred and when?

你自己回答了这个问题,所以我想不需要详细说明。

So, how know if a package will be heavy for the entire application or not?

剖析它。引导您的应用程序并测试负载。延迟和取消延迟提供以获取示例。

For example, I want to use the "cviebrock/eloquent-sluggable" package that is very simple and uses trait for add functionalities in the model. But also implements a service provided with bindings that will be used in an observer, how I know if this will be loaded only when I save or edit models?

任何实现了 boot 方法的提供者都不能延迟。这个包实现了 boot 方法。因此,这是一个自举服务提供者,将随每个请求一起加载。

关于php - Laravel - 延迟服务提供者如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48999587/

相关文章:

php - Wordpress:逐月获取帖子,布局问题

php - 如果 key 不存在则发送 null

caching - Eloquent 是否处理相关实体的缓存?

php - 在 handle 函数中获取中间件 laravel 中的请求值

php - 路由到 View 而不传递变量 - laravel

php - Laravel 5.2 php artisan 迁移 :rollback error

php - 如何让MySQL数据库出现在index.php上

javascript - 使用 Ajax 创建 session 并回显结果

php - 在 double 上调用成员函数 first()

php - 用户 ID 和用户名未插入关系