原文:http://www.yiiframework.com/doc-2.0/guide-runtime-bootstrapping.html
引导,指的是在应用程序开始解析和处理一个收到的请求之前准备环境的过程。引导具体在两处进行: 入口脚本 和 应用程序。
TBT.
In the entry script, class autoloaders for different libraries are registered. This includes the Composer autoloader through its autoload.php
file and the Yii autoloader through its Yii
class file. The entry script then loads the application configuration and creates an application instance.
In the constructor of the application, the following bootstrapping work is done:
- preInit() is called, which configures some high priority application properties, such as basePath.
- Register the error handler.
- Initialize application properties using the given application configuration.
- init() is called which in turn calls bootstrap() to run bootstrapping components.
- Include the extension manifest file
vendor/yiisoft/extensions.php
. - Create and run bootstrap components declared by extensions.
- Create and run application components and/or modules that are declared in the application’s bootstrap property.
- Include the extension manifest file
Because the bootstrapping work has to be done before handling every request, it is very important to keep this process light and optimize it as much as possible.
Try not to register too many bootstrapping components. A bootstrapping component is needed only if it wants to participate the whole life cycle of requesting handling. For example, if a module needs to register additional URL parsing rules, it should be listed in the bootstrap property so that the new URL rules can take effect before they are used to resolve requests.
In production mode, enable a bytecode cache, such as PHP OPcache or APC, to minimize the time needed for including and parsing PHP files.
Some large applications have very complex application configurations which are divided into many smaller configuration files. If this is the case, consider caching the whole configuration array and loading it directly from cache before creating the application instance in the entry script.
您必须登录才能发表评论。