引导后访问 Zend 应用程序引导 _init 函数 [英] Accessing the Zend Application Bootstrap _init Functions After Bootstrapping
问题描述
我为并行任务编写了一个基于 Zend 框架的 cron 服务,并且 运行子线程与父线程共享资源的问题.我解决了数据库连接问题,但我现在看到定期Zend_Db_Table_Abstract
无法将表元数据保存到元数据缓存的问题.
I have written a Zend Framework based cron service for parallel tasks, and ran into issues with the child threads sharing resources with the parent. I solved the database connection issue, but I'm now seeing periodic issues with Zend_Db_Table_Abstract
failing to save table metadata to metadata cache.
将元数据保存到 metadataCache 失败
Failed saving metadata to metadataCache
我在引导过程中初始化了元数据缓存.与其从引导程序复制我的代码并在分叉后执行,我认为最好使用 $application-> 调用
.Bootstrap->_init[...]
函数;bootstrap('[...]')
I initialize the metadata cache during bootstrap. Rather than copying my code from the bootstrap and executing after forking, I thought that it might be better to call the Bootstrap->_init[...]
functions by using $application->bootstrap('[...]')
.
更新
因为 Zend_Controller_Front::getInstance()
是一个单例,使用它来获取引导程序实例并调用这样的函数使我返回到与我已经解决的共享资源相同的问题.
Because Zend_Controller_Front::getInstance()
is a Singleton, using it to get the bootstrap instance and call the functions that way returns me to the same issue with shared resources that I had already resolved.
我想以某种方式保持这种 DRY,同时避免分叉后共享资源的问题.
I want to somehow keep this DRY while avoiding the issues with shared resources after forking.
推荐答案
Zend_Controller_Front 是单例的,但它的构造函数是受保护的,所以你可以简单地通过创建一个名为 App_Controller_Front 的类来扩展它
Zend_Controller_Front is singleton, but its constructor is protected, so you can extend that simply by creating a class called, App_Controller_Front
在其中为 getNewInstance() 创建一个方法,该方法可以调用构造函数而无需检查是否存在.这样你就可以覆盖单例行为.
in that create a method for getNewInstance(), which can call constructor without checking for existence. This way you can override the singleton behavior.
这篇关于引导后访问 Zend 应用程序引导 _init 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!