我一直在閱讀很多sites甚至here,爲了提高Zend Framework應用程序的性能,不是在引導程序中使用Zend_Application,而是一直未能找到具有這證明了。未使用Zend_Application的Zend Framework項目
你們知道一個地方有這種方法的描述,可能會提供一些代碼示例嗎?
感謝
我一直在閱讀很多sites甚至here,爲了提高Zend Framework應用程序的性能,不是在引導程序中使用Zend_Application,而是一直未能找到具有這證明了。未使用Zend_Application的Zend Framework項目
你們知道一個地方有這種方法的描述,可能會提供一些代碼示例嗎?
感謝
我只是把這個在一起:
https://gist.github.com/2822456
轉載如下完成。沒有測試,只是一些想法,我認爲它通常(!)可能工作。現在我已經經歷了一些,我對Zend_Application,它的引導類以及它的可配置/可重用應用程序資源有了更多的瞭解。 ;-)
// Do your PHP settings like timezone, error reporting
// ..
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/_zf/application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
// Get autoloading in place
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
// Any additional configs to autoloader, like custom autoloaders
// Read config
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
// bootstrap resources manually:
// * create db adapter
// * create resource autoloaders with the mappings you need
// * etc
// Get the singleton front controller
$front = Zend_Controller_Front::getInstance();
// Set controller directory
$front->setControllerDirectory(APPLICATION_PATH . '/controllers');
// Or set module directory
$front->setModuleDirectory(APPLICATION_PATH . '/modules');
// Other front config, like throw exceptions, etc.
// ...
//
// Create a router
$router = new Zend_Controller_Router_Rewrite();
// Add routes to the router
$router->addRoute('myRoute', new Zend_Controller_Router_Route(array(
// your routing params
)));
// More routes...
// Alternatively, the routes can all be in an xml or ini file and you can add
// them all at once.
// Tell front to use our configured router
$front->setRouter($router);
// Add an plugins to your $front
$front->registerPlugin(new My_Plugin());
// other plugins...
// Dispatch the request
$front->dispatch();
也可能有一些View/ViewRenderer的東西可以做。但正如其他地方所指出的那樣,ViewRenderer會帶來不平凡的性能。如果性能是問題,那麼你會希望禁止ViewRenderer,讓你的動作控制器調用使用$this->view->render('my/view-script.phtml')
當你調用$front->dispatch()
,在$request
和$response
對象將被自動創建自己的渲染。如果你想在bootstrap中做一些特定的事情 - 比如在響應的Content-Type頭中設置charset,那麼你可以自己創建你的請求/響應對象,按照你想要的做,然後將它附加到前端與$front->setResponse($response);
相同的請求對象。
雖然我看到我的示例使用Zend_Loader_Autoloader
和Zend_config_Ini
,Padraic注意到了性能問題。下一步是通過使用數組來配置,從框架中剝離require_once調用,註冊一個不同的自動加載器等等,這個練習留給讀者... ;-)
您好我在引導的不使用Zend_Application有點不同意,沒有我還沒有看到這種技術的具體例子。
就我個人而言,我認爲沒有看到Zend_app用於引導應用程序的好處,假設a)您的操作是'Zend方式'和b)您的項目要麼足夠大,要麼只是使用Zend框架或者就此而言)。
雖然Zend_App是偉大的標準化結構中創建一致的複雜白手起家 ,它不來沒有顯著 性能命中基準性能。更直接的引導程序 (ZF直到Zend_App到達爲止的典型值)要快得多,也可以在沒有配置文件的情況下完成 。
來自PádraicBrady link。
對我來說,上面沒有任何意義,他基本上只是說Zend_App對於複雜的bootstraps很棒,但是增加了性能。但是,這不是任何框架/框架組件的前提嗎?我知道Padraic是一個非常聰明的人,我確信他有他的推理,但我也很想看到這個建議的例子/證據。
也許在回答你的問題時,你可以使用最新的Zend框架對一個基本應用程序進行基準測試,然後使用Zend框架從< 1.10使用舊的非Zend_App方法,但我會說盡管顯然不完美Zend_App顯然更快讓大多數應用程序啓動並運行,因此,無論這是否值得「性能受到影響」,我都會向開發人員推薦。
這裏是一個鏈接,這在一定程度進入你是什麼之後,但提到了一個模塊化的方法(仍然有趣的,沒有少):
值得注意的是這個文件也超過2歲...我不知道自從那以後事情已經改變 –
我同意。 Zend_App工作得很好,很乾淨。 – conradfr
是的,甚至沒有測試用例和基準,這似乎有點不必要。我使用的技巧是刪除Zend庫的所有require/include。 – conradfr