blanchonvincent/zf2-lazy-loading-module
最新稳定版本:1.5.2
Composer 安装命令:
composer require blanchonvincent/zf2-lazy-loading-module
包简介
ZF2 Lazy Loading Module 1.5.2 - Provide a library to implements lazy loading module in ZF2
README 文档
README
Version 1.5.2 Created by Vincent Blanchon
Introduction
For this project, i redefined a party of the module manager to have a lazy loading and increase the performance. Project exemple is available on the loazy loading module website
Installation
- Install with composer :
Add the dependency in composer.json :
{
"require" : {
"blanchonvincent/zf2-lazy-loading-module" : "master-dev"
}
}
php composer.phar update
- Modify your ./init_autoloader.php :
<?php require_once __DIR__ . '/vendor/ZF2/library/Zend/Loader/AutoloaderFactory.php'; // Composer autoloading if (file_exists('vendor/autoload.php')) { $loader = include 'vendor/autoload.php'; } Zend\Loader\AutoloaderFactory::factory(array( 'Zend\Loader\StandardAutoloader' => array( 'autoregister_zf' => true, 'namespaces' => array( 'ZFMLL' => __DIR__ . '/vendor/blanchonvincent/zf2-lazy-loading-module', ), ), ));
- Modify your ./config/application.config.php :
<?php return array( 'modules' => array( // your modules ), 'module_listener_options' => array( 'module_paths' => array( './module', './vendor', ), 'config_glob_paths' => array( 'config/autoload/{,*.}{global,local}.php', ), 'lazy_loading' => array( // define here your rules ), ), 'service_manager' => array( 'factories' => array( 'ModuleManager' => 'ZFMLL\Mvc\Service\ModuleManagerFactory', ), ), );
Lazy Loading module usage
Lazy loading module concept can load only authorize module for the current environment. Exemple :
- I want load my "Administration" module only on port 443, and if my client ip is valid. Without that, to load this module is useless.
The config to load module only on port 443 and ip on white list, with config/application.config.php :
<?php return array( 'modules' => array( 'Application', 'Cron', 'Administration', 'Blog', ), 'module_listener_options' => array( 'config_glob_paths' => array( 'config/autoload/{,*.}{global,local}.php', ), 'config_cache_enabled' => false, 'cache_dir' => 'data/cache', 'module_paths' => array( 'Application' => './module/Application', 'Cron' => './module/Cron', 'Administration' => './module/Administration', 'Blog' => './module/Blog', ), 'lazy_loading' => array( 'Administration' => array( 'port' => '443', 'remote_addr' => array('127.0.0.1'), ), ), ), 'service_manager' => array( 'factories' => array( 'ModuleManager' => 'ZFMLL\Mvc\Service\ModuleManagerFactory', ), ), ); ?>
- I want load my "Cron" module only in "cli" sapi and run url in argument :
<?php return array( 'modules' => array( 'Application', 'Cron', 'Administration', 'Blog', ), 'module_listener_options' => array( 'config_glob_paths' => array( 'config/autoload/{,*.}{global,local}.php', ), 'config_cache_enabled' => false, 'cache_dir' => 'data/cache', 'module_paths' => array( 'Application' => './module/Application', 'Cron' => './module/Cron', 'Administration' => './module/Administration', 'Blog' => './module/Blog', ), 'lazy_loading' => array( 'Cron' => array( 'getopt' => array('cron=s' => 'cron url'), 'sapi' => 'cli', ), ), ), 'service_manager' => array( 'factories' => array( 'ModuleManager' => 'ZFMLL\Mvc\Service\ModuleManagerFactory', ), ), ); ?>
Filter available are : argument in command line, sapi, domain, https protocol, server port, url and remote address.
The cache key will be automatically update with the module loaded.
Benchmark
Benchmark condition :
- no module cache enable
- 100 modules loading, for each test
- homepage action
- lastest master branch version (at the May 1st)
In the first case :
- 4 modules : Application, Administration, Cron and Blog
- In each other Application module, a simple class (like in the project code) :
<?php class Module implements AutoloaderProvider { public function init(Manager $moduleManager) { } public function getAutoloaderConfig() { return array( 'Zend\Loader\ClassMapAutoloader' => array( __DIR__ . '/autoload_classmap.php', ), ); } public function getConfig() { return include __DIR__ . '/config/module.config.php'; } }
=> ZFMLL performance increases up to 5% on the module loading.
In the seconde case :
- 4 modules : Application, Administration, Cron and Blog
- Cron & Blog have minimal class Module and Administration attach three listeners (listeners function are empty) :
<?php $events = $manager->events()->getSharedManager(); $events->attach('application', MvcEvent::EVENT_BOOTSTRAP, array($this, 'firstListener'), 100); $events->attach('application', MvcEvent::EVENT_BOOTSTRAP, array($this, 'secondListener'), 100); $events->attach('Zend\ModuleManager\ModuleManager', 'loadModules.post', array($this, 'thirdListener'), -100);
=> ZFMLL performance increases **up to 55%**on the module loading.
In the third case :
- 4 modules :Application, Administration, Cron and Blog
- Administration attach the same listeners with the second case, and Blog attach two listeners (listener function are empty) :
<?php $events = $manager->events()->getSharedManager(); $events->attach('application', MvcEvent::EVENT_BOOTSTRAP, array($this, 'firstListener'), 100); $events->attach('application', MvcEvent::EVENT_BOOTSTRAP, array($this, 'secondListener'), 100);
=> ZFMLL performance increases up to 60% on the module loading.
With a real code in the several listeners, ZFMLL can increase more of 75% performance on the module loading !
blanchonvincent/zf2-lazy-loading-module 适用场景与选型建议
blanchonvincent/zf2-lazy-loading-module 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.71k 次下载、GitHub Stars 达 35, 最近一次更新时间为 2013 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 blanchonvincent/zf2-lazy-loading-module 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blanchonvincent/zf2-lazy-loading-module 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 35
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-01-06