Optimising the Zend Framework

后端 未结 5 1059
耶瑟儿~
耶瑟儿~ 2020-12-08 08:44

I\'m trying to get as much performance as I can out of my application, which uses the Zend Framework.

I\'m considering using the Zend Server, with APC enabled. Howev

5条回答
  •  星月不相逢
    2020-12-08 09:13

    The Source This tip is not new. It is taken directly from the Zend Framework Documentation at: Zend Framework Performance Guide and I used what was written with few things I’ve skip.

    Use Zend_Loader and Remove All require_once

    We can’t actually remove all require_once statements. We must have at least one require_once to load the Zend_Loader. First, activate Zend Loader.

    require_once 'Zend/Loader.php';
    Zend_Loader::registerAutoload();
    

    Next would be removing all require_once statements on all files inside the Zend directory. If you are using Eclipse PDT, you can use the find and replace function.

    Cache Zend_Db_Table MetaData with Zend_Cache

    When you are using Zend_Db_Table (I sometimes only used Zend_Db) you will notice that when you try to retrieve data from the database, the first query called is to DESCRIBE the table. Zend_Db_Table uses the information on DESCRIBE query to do its magic on SELECT.

    As I have profiled my queries, I noticed that DESCRIBE query is the longest query (in most cases) which mean a big overhead over you retrieval operation. You have two options:

    (A) Don’t use Zend_Db_Table (go for Zend_Db) (B) Cache the MetaData

    On this post, I’ll use the caching of MetaData. On your bootstrap file, put this piece of code:

    //Caching
    $frontendOptions = array(
                        'lifetime'                  => 25200,
                        'automatic_serialization'   => true
                        );
    $backendOptions  = array(
                         'cache_dir'                => APPLICATION_PATH . '/tmp'
                        );          
    $cache = Zend_Cache::factory(
                        'Core',
                        'File',
                        $frontendOptions,
                        $backendOptions
                        );
    //Cache table metadata
    Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
    

    Cache Plugin Loader Class File

    When using a plugin, Zend Framework includes several files depending on the plugin used and process several iterations to find the right plugin and include it. With code code below, it creates a list of include_once statements to include those plugin files. Just include this piece of code to your bootstrap.

    //Plugin Loader caching
    $classFileIncCache = APPLICATION_PATH .  '/data/pluginLoaderCache.php';
    if (file_exists($classFileIncCache)) {
        include_once $classFileIncCache;
    }
    Zend_Loader_PluginLoader::setIncludeFileCache($classFileIncCache);
    

    Caching Your Data

    Caching your data will be the most important part of optimization which will save you a lot of database access when repeatedly accessed data already cache. It is important to set the cache expiration time and also clear the cache when data changes. A simple caching is shown below.

    On your bootstrap:

    //Caching
    $frontendOptions = array(
                        'lifetime'                  => 25200,
                        'automatic_serialization'   => true
                        );
    $backendOptions  = array(
                         'cache_dir'                => APPLICATION_PATH . '/tmp'
                        );          
    $cache = Zend_Cache::factory(
                        'Core',
                        'File',
                        $frontendOptions,
                        $backendOptions
                        );
    
    $registry->set('cache', $dbCache);
    

    This are the basic settings which may helpful I think.

提交回复
热议问题