jac*_*cnr 4 php zend-framework zend-cache zend-config
我的Zend应用程序使用3个ini配置文件,总共超过200行进行解析,包含100多条指令.每个请求都解析这些文件吗?有人说他们(就像这里和这里一样).如果是这样,这不是效率问题吗?
这些链接中的评论含糊不清 - 有人说你应该避免ini配置文件并在PHP中进行配置,有人说你可以使用Zend_Cache_Frontend_File,有些人说这不是问题.但是,如果您预计会有相当多的流量,那么为每个请求分析200行文本肯定会很快成为问题吗?
如果您的确建议使用缓存技术,请详细说明如何实现缓存技术?
Mar*_*cin 10
是的,除非您缓存它们,否则每次都会对它们进行解析.它确实节省了时间(我在自己的项目中检查过).
那么你如何使用Zend_Cache_Frontend_File缓存ini文件?好吧,我可以为你提供一个例子.在我的项目中,我有route.ini文件,其中包含许多自定义路由:
routes.ini
routes.showacc.route = "/@show/:city/:id/:type"
routes.showacc.type = "Zend_Controller_Router_Route"
routes.showacc.defaults.module = default
routes.showacc.defaults.controller = accommodation
routes.showacc.defaults.action = show
routes.showacc.defaults.city =
routes.showacc.defaults.type =
routes.showacc.defaults.id =
routes.showacc.defaults.title =
routes.showacc.reqs.id = "\d+"
;and more
Run Code Online (Sandbox Code Playgroud)
在我的Bootstrap.php中,我使用缓存加载它们(如果可能):
protected function _initMyRoutes() {
$this->bootstrap('frontcontroller');
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
// get cache for config files
$cacheManager = $this->bootstrap('cachemanager')->getResource('cachemanager');
$cache = $cacheManager->getCache('configFiles');
$cacheId = 'routesini';
// $t1 = microtime(true);
$myRoutes = $cache->load($cacheId);
if (!$myRoutes) {
// not in cache or route.ini was modified.
$myRoutes = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini');
$cache->save($myRoutes, $cacheId);
}
// $t2 = microtime(true);
// echo ($t2-$t1); // just to check what is time for cache vs no-cache scenerio
$router->addConfig($myRoutes, 'routes');
}
Run Code Online (Sandbox Code Playgroud)
缓存在我的application.ini中设置如下
resources.cachemanager.configFiles.frontend.name = File
resources.cachemanager.configFiles.frontend.customFrontendNaming = false
resources.cachemanager.configFiles.frontend.options.lifetime = false
resources.cachemanager.configFiles.frontend.options.automatic_serialization = true
resources.cachemanager.configFiles.frontend.options.master_files[] = APPLICATION_PATH "/configs/routes.ini"
resources.cachemanager.configFiles.backend.name = File
resources.cachemanager.configFiles.backend.customBackendNaming = false
resources.cachemanager.configFiles.backend.options.cache_dir = APPLICATION_PATH "/../cache"
resources.cachemanager.configFiles.frontendBackendAutoload = false
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
8752 次 |
| 最近记录: |