2010-10-25 22 views
6

Zend Optimizer'ın yanı sıra Zend-Framwork çalışmasını daha hızlı yapmanın en iyi yolları nelerdir?Zend Framework'ün daha hızlı çalışmasını sağlama

Doğru hatırlıyorsam, PHP'de paring .ini dosyalarını uzun zaman alır. Bunun için önbellek (dosya bir istek sırasında değişmeyecek)

ZF'nin performansını iyileştirmenin başka yolları var mı?

cevap

8

bu gibi benim application.ini önbelleğe:

Eğer (önbellek dir) şu dizini olduğundan emin olun:

<?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; 
    } 
} 
: Ben My_Application ile Zend_Application uzatmak /application/data/cache

, kodu görmek

Ve index.php dizinini (public kökünde) aşağıdaki gibi değiştirin:

<?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(); 

Sayfayı yeniden yükleyin ve ini dosyasının önbelleğe alınmış olduğunu görürsünüz. İyi şanslar.

+2

application.ini önbelleğe performans artışı nedir? Bunun için ölçütleriniz var mı? –

+0

Bu, ini dosyanızın boyutuna bağlıdır. CSS dosyanızı önbelleğe alma ve önbellekle birlikte veya önbellek yükleme gibi görün. (Ini-heavy) uygulamamda –

+0

@Jurian% 2-5. – ReactiveRaven

5

görüyorum, ama bu tipik bir ZF uygulamasının en yavaş parçası yakınından bile olmak istemem. Herhangi bir sonuç görmeden, bir grup dosyayı (Zend_Cache_ *) dahil etmek, bazı durumlarda basit bir .ini dosyasını ayrıştırmaktan daha yavaş olabilir. Tam veritabanı sorgularını/kompleks işlemleri,: Kısacası http://framework.zend.com/manual/en/performance.classloading.html

,

  1. bu konularda önbelleğe alma yararlanın: Neyse, bu

    ZF optimizasyonu üzerinde iyi bir rehber yayınladı

    ... sadece bir alandır sayfa önbelleği, vb.

  2. Şerit gereksinimleri_once, belgelere göre otomatik yükleme lehine çağrılar yapar.
  3. Önbellek PluginLoader dosya/sınıf haritası bunu içine biraz daha fazla almak istiyorsanız

, op-kod önbelleği çeşit etkinleştirme Zend_Application bileşeni

  • kullanılarak

    1. Atla
    2. Diğer tipik PHP eniyileme yöntemleri (profil oluşturma, bellek önbellekleme, vb.)
  • +0

    Zend_Cache_ *, opcode önbelleğinde olduğunda, artık yavaş değiller. Ayrıştırılan INI dosyasını önbelleğe almazsanız, her zaman yavaş olacaktır. Uygulamamda, optimizasyona başlamadan önce, INI dosyalarını ayrıştırmak bir isteğin büyük çoğunluğu (% 75-90) idi. Yapılandırma kolaylığı için harika, hız için çok sıcak değil. – ReactiveRaven

    +0

    İsteğinizin% 75-90'ı? Sen ciddisin ? – Maxence

    +0

    Önyükleme işlemini okumanın kusura bakmayın. Tüm Zend_Application/bootstrap işlemi% 70 idi. Zend_Config aslında oldukça yavaştı, ama kesinlikle% 70 değil. –