zend framework性能优化技巧总结

1.设置插件类路径的缓存(将以下代码放入引导文件中)

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

2.启用autoloader机制
然后注释require_once语句

% cd path/to/ZendFramework/library
% find . -name '*.php' -print0 | xargs -0 \
  sed --regexp-extended --in-place 's/(require_once)/\/\/ \1/g'

3.缓存配置为数组
Zend_Application 加载配置文件的时候,其文件可以是一个返回数组的值,后缀名因为.inc或.php的文件。

<?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(
    'E:\Inetpub\ZendFramework-1.8.2\library',
    get_include_path(),
)));

define('APPLICATION_INI',APPLICATION_PATH . '/configs/application.ini');
define('APPLICATION_INC',APPLICATION_PATH . '/../data/configCache.php');
//配置缓存处理函数返回路径
function loadConfigCache($ini, $inc, $environment){
//	if ( 'development' === $environment) {
//		return $ini;
//	}
    if (!file_exists($inc)) {
    	if ( !file_exists(dirname($inc)) || !is_writable(dirname($inc) )) {
    		throw new Exception('Specified file is not writeable (' . $inc . ')');
    	}
    	require_once 'Zend/Config/Ini.php';
    	$config = new Zend_Config_Ini($ini, $environment);
        $configs = '<?php' . PHP_EOL . 'return ' . var_export($config->toArray(), true) . PHP_EOL . '?>';
        file_put_contents($inc, $configs);
    }
    return $inc;
}
//loadConfigCache(APPLICATION_INI,APPLICATION_INC,APPLICATION_ENV);
/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    loadConfigCache(APPLICATION_INI,APPLICATION_INC,APPLICATION_ENV)
);
$application->bootstrap()
            ->run();

Blueprint[css framework]

使用一种CSS框架理由很简单,提高开发效率,和更简便布局方法

下面将简单介绍blueprint的使用方法:

安装

把以下代码放置到页面<head>中:

  <!-- Framework CSS -->
	<link rel="stylesheet" href="../../blueprint/screen.css" type="text/css" media="screen, projection">
	<link rel="stylesheet" href="../../blueprint/print.css" type="text/css" media="print">
  <!--[if lt IE 8]><link rel="stylesheet" href="../../blueprint/ie.css" type="text/css" media="screen, projection"><![endif]-->
Blueprint的文件介绍
  • blueprint/screen.css  正常显示样式
  • blueprint/print.css  打印的样式
  • blueprint/ie.css 只在IE中使用去除不兼容情形

在src文件夹中样式文件是对上述3个文件细分

  • blueprint/src/reset.css:  重置浏览器样式.统一各浏览器的样式
  • blueprint/src/grid.css: 格子的样式,配合div标签使用进行列网格设置.
  • blueprint/src/typography.css: 设置排版样式,对重置后元素加上统一样式.
  • blueprint/src/forms.css: Includes some minimal styling of forms.
  • blueprint/src/print.css: 设置默认打印样式.
  • blueprint/src/ie.css: 包含Ie6、7的hack
格子使用.

默认情况下格子整体宽950px,有24列,列距是30px,右外距10px,如下计算

Total width = (columns * 40) - 10 
  <div class="container">
    <div class="span-24">Header </div>
    <div class="span-4">Left sidebar </div>
    <div class="span-16">
      <div class="span-8">Box1 </div>
      <div class="span-4">Box2 </div>
      <div class="span-4 last">Box3 </div>
      <div class="span-16 last">Main content </div>
    </div>
    <div class="span-4 last">Right sidebar </div>
    <div class="span-24">Footer </div>
  </div>

注意:

  • 使用“last” class 在最后一栏的时候(除了类为span-24)
  • 确保 一行列数总和等于是其父标签的列数(就使宽度相等)

其他资源:

Blueprint CSS Framework 学习笔记-概述