Question

Quelles sont les meilleures façons de faire Zend-Framwork courir plus vite en plus Zend Optimizer?

Si je me souviens bien, l'analyse des fichiers .ini en PHP prend beaucoup de temps. Je en cache à cet effet (le fichier ne changera pas au cours d'une demande)

Y at-il d'autres moyens d'améliorer la performance de ZF?

Était-ce utile?

La solution

Je mettre en cache mon application.ini Comme ceci:

Assurez-vous que vous avez le répertoire suivant (cache dir): /application/data/cache

J'adresse Zend_Application avec My_Application, voir code:

<?php
require_once 'Zend/Application.php';

class My_Application extends Zend_Application
{

    /**
     * Flag used when determining if we should cache our configuration.
     */
    protected $_cacheConfig = false;

    /**
     * Our default options which will use File caching
     */
    protected $_cacheOptions = array(
        'frontendType' => 'File',
        'backendType' => 'File',
        'frontendOptions' => array(),
        'backendOptions' => array()
    );

    /**
     * Constructor
     *
     * Initialize application. Potentially initializes include_paths, PHP
     * settings, and bootstrap class.
     *
     * When $options is an array with a key of configFile, this will tell the
     * class to cache the configuration using the default options or cacheOptions
     * passed in.
     *
     * @param  string                   $environment
     * @param  string|array|Zend_Config $options String path to configuration file, or array/Zend_Config of configuration options
     * @throws Zend_Application_Exception When invalid options are provided
     * @return void
     */
    public function __construct($environment, $options = null)
    {
        if (is_array($options) && isset($options['configFile'])) {
            $this->_cacheConfig = true;

            // First, let's check to see if there are any cache options
            if (isset($options['cacheOptions']))
                $this->_cacheOptions =
                    array_merge($this->_cacheOptions, $options['cacheOptions']);

            $options = $options['configFile'];
        }
        parent::__construct($environment, $options);
    }

    /**
     * Load configuration file of options.
     *
     * Optionally will cache the configuration.
     *
     * @param  string $file
     * @throws Zend_Application_Exception When invalid configuration file is provided
     * @return array
     */
    protected function _loadConfig($file)
    {
        if (!$this->_cacheConfig)
            return parent::_loadConfig($file);

        require_once 'Zend/Cache.php';
        $cache = Zend_Cache::factory(
            $this->_cacheOptions['frontendType'],
            $this->_cacheOptions['backendType'],
            array_merge(array( // Frontend Default Options
                'master_file' => $file,
                'automatic_serialization' => true
            ), $this->_cacheOptions['frontendOptions']),
            array_merge(array( // Backend Default Options
                'cache_dir' => APPLICATION_PATH . '/data/cache'
            ), $this->_cacheOptions['backendOptions'])
        );

        $config = $cache->load('Zend_Application_Config');
        if (!$config) {
            $config = parent::_loadConfig($file);
            $cache->save($config, 'Zend_Application_Config');
        }

        return $config;
    }
}

Et je change mon index.php (à la racine de public) à:

<?php

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../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(),
)));

/** My_Application */
require_once 'My/Application.php';

// Create application, bootstrap, and run
$application = new My_Application(
    APPLICATION_ENV,
    array(
            'configFile' => APPLICATION_PATH . '/configs/application.ini'
    )
);
$application->bootstrap()
            ->run();

Recharger la page et que vous voyez le fichier ini mis en cache. Bonne chance.

Autres conseils

Les fichiers de l'analyse syntaxique un peu lent, mais je ne m'y attendais pas à être près de la partie la plus lente d'une application typique de ZF. Sans y voir aucun résultat, il semble que, y compris un tas de fichiers (Zend_Cache_ *) peut, dans certains cas, être encore plus lent que l'analyse d'un fichier .ini simple. Quoi qu'il en soit, c'est juste un endroit ...

ZF a publié un guide sur l'optimisation: http://framework.zend.com/manual/en/performance.classloading.html

En bref,

  1. Utiliser la mise en cache où il importe:. Requêtes de base de données / opérations complexes, cache pleine page, etc
  2. Strip appels require_once en faveur de l'auto-chargement comme par la documentation.
  3. fichier Cache PluginLoader / carte de classe

Si vous voulez obtenir un peu plus en elle,

  1. Sauter en utilisant le composant Zend_Application
  2. Activer une sorte de cache op-code
  3. Est-ce que d'autres méthodes d'optimisation de PHP (type de profilage, la mise en cache de la mémoire, etc.)

Pourquoi avez-vous supprimé votre dernière question? J'ai eu un bon lien pour vous:

  

J'ai entendu des choses comme ça avant, mais   la combinaison est souvent liée à   la migration d'une plate-forme à l'autre.

     

Vérifiez à ce lien:

     

http: //devblog.policystat. com / php-à-django-changeant-the-moteur en cours de la-c

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top