私はここでも多くのサイトで、Zend Frameworkアプリケーションのパフォーマンスを向上させるためにブートストラップでZend_Applicationを使用しないことを読んでいますが、これが実証されているサイトを見つけることができませんでした。
このメソッドが説明されている場所を知っていて、コードサンプルを提供してくれる可能性がありますか?
ありがとう
I just threw this together:
https://gist.github.com/2822456
Reproduced below for completion. Not tested, just some ideas for how I think it generally (!) might work. Now that i have walked through it a bit, I have a greater appreciation for Zend_Application, its bootstrap classes, and its configurable/reusable application resources. ;-)
// 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();
There might be some View/ViewRenderer stuff to do, as well. But as noted in other places, the ViewRenderer incurs a non-trivial performance hit. If performance is the issue, then you'll want to disable the ViewRenderer and make your action controllers call their own rendering using $this->view->render('my/view-script.phtml')
When you call $front->dispatch()
, the $request
and $response
objects will be created automatically. If you want to do something specific to them at bootstrap - like setting the charset in Content-Type header of the response - then you can create your request/response object yourself, do what you want to it, and then attach it to the front with $front->setResponse($response);
Same for the request object.
Although I see that my example uses Zend_Loader_Autoloader
and Zend_config_Ini
which Padraic notes incur performance hits. The next step would be to address those by using arrays for config, stripping require_once calls from the framework, registering a different autoloader, etc, an exercise left for the reader... ;-)
こんにちは私はブートストラップでZend_Applicationを使用しないことにいくらか同意しません。また、この手法の具体的な例はまだ見ていません。
個人的には、アプリケーションのブートストラップにZend_appを使用しないことのメリットはわかりません。ただし、a)「Zendの方法」を実行し、b)プロジェクトが十分に大きいか、単にZendフレームワーク(またはそのためのいずれか)を使用する必要があると仮定します。案件)。
Zend_Appは、標準化された構造内で一貫性のある複雑なブートストラップを作成するのに最適ですが、ベースラインパフォーマンスに大きなパフォーマンスの影響を与えることなく実現することはできません。より直接的なブートストラップ(Zend_Appが到着するまでの通常のZF)ははるかに高速であり、構成ファイルなしでも実行できます。
PádraicBradyリンクから取得。
私にとって、上記は意味がありません。彼は基本的に、Zend_Appは複雑なブートストラップに最適であると述べましたが、パフォーマンスに影響を与えます。しかし、それはフレームワーク/フレームワークコンポーネントの前提ではありませんか?パドレイクは非常に賢い人であり、彼には彼の推論があると確信していますが、私もこの提案の例/証拠を見たいと思っています。
おそらくあなたの質問に答えて、最新のZendフレームワークを使用して基本的なアプリをベンチマークし、古い非Zend_Appの方法を使用して1.10未満のZendフレームワークを使用することができますが、明らかに完全ではありませんが、Zend_Appはほとんどのアプリを起動するのに明らかに高速です実行しているので、これが「パフォーマンスヒット」の価値があるかどうかは、開発者次第だと思います。
これはあなたが何を求めているのかをいくらか説明しているが、モジュラーアプローチを参照しているリンクです(それでも興味深いですが):