September 14, 2013 | In: How-to vychytávky, Programovanie
Zend 1.12 optimization – class autoloader + class map + memcache
predtym som ale musel do classmap_generator.php pridat:
require $libPath . '/Zend/Console/Getopt.php';
require $libPath . '/Zend/File/ClassFileLocator.php';
Spustit classmap generator
prejdeme do zlozky so ZF 1.12 a potom v konzole spustit generator:
cd zendframework1/bin
$ php classmap_generator.php -l '../library/Zend/'
vytvori:
zendframework1/bin/library/Zend/autoload_classmap.php
Include classautoloader
ako bonus dostaneme Namespaces v zend 1.12 ako jeho bocny produkt
// index.php Zend_Loader_AutoloaderFactory::factory(array( 'Zend_Loader_ClassMapAutoloader' => array( '/var/www/dev/library/vendor/zendframework/zendframework1/library/Zend/autoload_classmap.php', // '/var/www/dev/library/v3/My_Libs.../autoload_classmap.php', ), 'Zend_Loader_StandardAutoloader' => array( 'prefixes' => array( 'Zend' => PATH_ZEND ), 'fallback_autoloader' => true ) ));
alebo jednoducho, no bez tohoto nemame namespaces:
require_once 'Zend/Loader/ClassMapAutoloader.php'; $loader = new Zend_Loader_ClassMapAutoloader(); // Register the class map: $loader->registerAutoloadMap($zendClassMapPath); // Register with spl_autoload: $loader->register();
Zend optimization – zrychlit pristup na disk
DOLEZITE: treba vyhodit vsetky require
find ./ -name '*.php' \
-not -wholename '*/Application.php' \
-not -wholename '*/Loader*' \
-print0 | xargs -0 \
sed --regexp-extended \
--in-place 's/(require_once)/\/\/ \1/g'
Zend config optimalizacia
// index.php $configKey = 'PATH_FILE_ZEND_APPLICATION_CONFIG'; $mc = new Memcache(); $mc->connect('localhost', 11211); $config = $mc->get($configKey); if (!is_array($config)) { $config = new Zend_Config_Ini(PATH_FILE_ZEND_APPLICATION_CONFIG, APPLICATION_ENV); $config = $config->toArray(); $mc->set($configKey, $config, false, 600); } // Create application, bootstrap, and run (new Zend_Application(APPLICATION_ENV, $config))->bootstrap()->run();
Comments are closed.