嗨!阳光![夸父:QQ2050479]
百度首页 | 百度空间
 
文章列表
 
2008年10月07日 星期二 13:19
mkdir /home/u1 创建文件夹/home/u1
chown oracle /home/u1 表示改变目录所有者为oracle账户;
chgrp dba /home/u1 改变/home/u1目录为dba所有;
chmod 755 /home/u1 表示oracle账户对/home/u1目录有755权限;
rmdir /home/u1 表示删除/home/u1目录

hostname可以查看linux的计算机名;
whoami可以查看当前用户;
pwd显示当前路径;
df查看系统的硬件信息
ls -lrt l表示显示详细列表,-t表示按时间排序,-r反向排序

cat orcl_ora_3436.trc|grep bucket

以下查看相关文件内容:
more /etc/oratab
cat /etc/passwd
cat /etc/group

转载自:
http://www.blogjava.net/Sunspl/archive/2008/07/28/217934.html
 
2008年10月07日 星期二 10:35
进入vi的命令
vi filename :打开或新建文件,并将光标置于第一行首
vi +n filename :打开文件,并将光标置于第n行首
vi + filename :打开文件,并将光标置于最后一行首
vi +/pattern filename:打开文件,并将光标置于第一个与pattern匹配的串处
vi -r filename :在上次正用vi编辑时发生系统崩溃,恢复filename
vi filename....filename :打开多个文件,依次进行编辑

移动光标类命令
h :光标左移一个字符
l :光标右移一个字符
space:光标右移一个字符
Backspace:光标左移一个字符
k或Ctrl+p:光标上移一行
j或Ctrl+n :光标下移一行
Enter :光标下移一行
w或W :光标右移一个字至字首
b或B :光标左移一个字至字首
e或E :光标右移一个字至字尾
) :光标移至句尾
( :光标移至句首
}:光标移至段落开头
{:光标移至段落结尾
nG:光标移至第n行首
n+:光标下移n行
n-:光标上移n行
n$:光标移至第n行尾
H :光标移至屏幕顶行
M :光标移至屏幕中间行
L :光标移至屏幕最后行
0:(注意是数字零)光标移至当前行首
$:光标移至当前行尾

屏幕翻滚类命令
Ctrl+u:向文件首翻半屏
Ctrl+d:向文件尾翻半屏
Ctrl+f:向文件尾翻一屏
Ctrl+b;向文件首翻一屏
nz:将第n行滚至屏幕顶部,不指定n时将当前行滚至屏幕顶部。

插入文本类命令
i :在光标前
I :在当前行首
a:光标后
A:在当前行尾
o:在当前行之下新开一行
O:在当前行之上新开一行
r:替换当前字符
R:替换当前字符及其后的字符,直至按ESC键
s:从当前光标位置处开始,以输入的文本替代指定数目的字符
S:删除指定数目的行,并以所输入文本代替之
ncw或nCW:修改指定数目的字
nCC:修改指定数目的行

删除命令
ndw或ndW:删除光标处开始及其后的n-1个字
do:删至行首
d$:删至行尾
ndd:删除当前行及其后n-1行
x或X:删除一个字符,x删除光标后的,而X删除光标前的
Ctrl+u:删除输入方式下所输入的文本

搜索及替换命令
/pattern:从光标开始处向文件尾搜索pattern
?pattern:从光标开始处向文件首搜索pattern
n:在同一方向重复上一次搜索命令
N:在反方向上重复上一次搜索命令
:s/p1/p2/g:将当前行中所有p1均用p2替代
:n1,n2s/p1/p2/g:将第n1至n2行中所有p1均用p2替代
:g/p1/s//p2/g:将文件中所有p1均用p2替换

选项设置
all:列出所有选项设置情况
term:设置终端类型
ignorance:在搜索中忽略大小写
list:显示制表位(Ctrl+I)和行尾标志($)
number:显示行号
report:显示由面向行的命令修改过的数目
terse:显示简短的警告信息
warn:在转到别的文件时若没保存当前文件则显示NO write信息
nomagic:允许在搜索模式中,使用前面不带“\”的特殊字符
nowrapscan:禁止vi在搜索到达文件两端时,又从另一端开始
mesg:允许vi显示其他用户用write写到自己终端上的信息

最后行方式命令
:n1,n2 co n3:将n1行到n2行之间的内容拷贝到第n3行下
:n1,n2 m n3:将n1行到n2行之间的内容移至到第n3行下
:n1,n2 d :将n1行到n2行之间的内容删除
:w :保存当前文件
:e filename:打开文件filename进行编辑
:x:保存当前文件并退出
:q:退出vi
:q!:不保存文件并退出vi
:!command:执行shell命令command
:n1,n2 w!command:将文件中n1行至n2行的内容作为command的输入并执行之,若不指定n1,n2,则表示将整个文件内容作为command的输入
:r!command:将命令command的输出结果放到当前行

寄存器操作
"?nyy:将当前行及其下n行的内容保存到寄存器?中,其中?为一个字母,n为一个数字
"?nyw:将当前行及其下n个字保存到寄存器?中,其中?为一个字母,n为一个数字
"?nyl:将当前行及其下n个字符保存到寄存器?中,其中?为一个字母,n为一个数字
"?p:取出寄存器?中的内容并将其放到光标位置处。这里?可以是一个字母,也可以是一个数字
ndd:将当前行及其下共n行文本删除,并将所删内容放到1号删除寄存器中。
 
2008年09月18日 星期四 13:48
 
2008年09月18日 星期四 13:07
下载php_svn.dll (先进入页面,再选择不同版本下载,勿右键另存!)
http://pecl4win.php.net/ext.php/php_svn.dll

配置php.ini
extension=php_svn.dll

* 重启Apache后,在phpinfo里没有发现svn扩展,也没有错误提示信息。


进入命令行:php -c c:\php\php.ini -m
出现错误信息,提示没有找到libdb43.dll

进入subversion目录:C:\Program Files\Subversion\bin,发现只有libdb44.dll(版本太新),拷贝libdb44.dll,改名为libdb43.dll,糊弄一下。
* 确认C:\Program Files\Subversion\bin目录在PATH环境变量内,以便系统能找到libdb43.dll。

重启Apache服务。



测试一下:<?php print_r(svn_ls('http://svn.red-bean.com/svnbook')); ?>

官方文档能查到函数列表:http://www.php.net/manual/en/ref.svn.php

---------------------------
转载自:老王的BLOG
hi.baidu.com/thinkinginlamp/blog/item/5e2a0208383a9cd763d98642.html
 
2008年09月17日 星期三 11:03
http://teethgrinder.co.uk/open-flash-chart/
 
2008年09月16日 星期二 16:54
在Windows下,按以下步骤,即可轻松安装Memcache:

1. 下载,并解压到目录(如:c:\php\memcached)
链接地址:jehiah.cz/projects/memcached-win32/files/memcached-1.2.1-win32.zip
如不可用,请搜索 memcache下载

2. 安装
在命令行(CMD)下输入:
c:\php\memcached\memcached.exe -d install

3. 将Memcached加入系统服务:
在命令行(CMD)下输入:
c:\memcached\memcached.exe -d start

4. 下载 php_memcache.dll 到 /php x.x/ext 目录
下载地址:pecl4win.php.net/ext.php/php_memcache.dll
注意:不能右键直接下载,因为这是一个页面,进入后会不同版本可供下载,PHP4 - PHP6..

5. 在 php.ini 加入一行 extension=php_memcache.dll

6.重新启动Apache。


memcached的基本设置:
-p 监听的端口
-l 连接的IP地址, 默认是本机
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop|shutdown 关闭正在运行的memcached服务
-d install 安装memcached服务
-d uninstall 卸载memcached服务
-u 以的身份运行 (仅在以root运行的时候有效)
-m 最大内存使用,单位MB。默认64MB
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是1024
-f 块大小增长因子,默认是1.25
-n 最小分配空间,key+value+flags默认是48
-h 显示帮助


Memcache环境测试:
运行下面的php文件,如果有输出This is a test!,就表示环境搭建成功。开始领略Memcache的魅力把!
<?php
$mem = new Memcache;
$mem->connect("127.0.0.1", 11211);
$mem->set("key", "This is a test!", 0, 60);
$val = $mem->get("key");
echo $val;
?>
 
2008年07月31日 星期四 17:57
/**
* 获得用户的真实IP地址
* @return string
*/
function real_ip() {
    static $realip = NULL;
    if (is_null($realip)) {
      if (isset($_SERVER)) {
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
          $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
          foreach ($arr AS $ip) {
            $ip = trim($ip);
            if ($ip != 'unknown') {
              $realip = $ip; break;
            }
          }
        } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
          $realip = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (isset($_SERVER['REMOTE_ADDR'])) {
          $realip = $_SERVER['REMOTE_ADDR'];
        } else {
          $realip = '0.0.0.0';
        }
      } else {
        if (getenv('HTTP_X_FORWARDED_FOR')) {
          $realip = getenv('HTTP_X_FORWARDED_FOR');
        } elseif (getenv('HTTP_CLIENT_IP')) {
          $realip = getenv('HTTP_CLIENT_IP');
        } else {
          $realip = getenv('REMOTE_ADDR');
        }
      }
      preg_match("/[\d\.]{7,15}/", $realip, $onlineip);
      $realip = !empty($onlineip[0]) ? $onlineip[0] : '0.0.0.0';
    }
    return $realip;
}
 
2008年07月16日 星期三 16:10
1. CSS字体定义简写规则
一般写法:
    font-weight: bold;font-style: italic;font-varient:small-caps;font-size:1em;line-height:1.5em;font-family:verdana,sans-serif
简洁写法:
    font: bold italic small-caps 1em/1.5em verdana,sans-serif
简写注意:
    A.必须提供 font-size 和 font-family 这两个属性
    B.同时font-weight, font-style 以及 font-varient 默认 normal

2. background
DIV.comment{background:#f0f0f0 url(url address) repeat-x left top}

3. border
给DIV加边框:
DIV.special{border:1px solid color4}
定义div四边的颜色不同:
DIV.special{border:1px solid; border-color:color1 color2 color3 color4}

4. 同时使用多个Class定义
<p class="css1 css2">...</p>

5. CSS border的缺省值
通常定义border属性会提供color,width,style属性,实际必须提供的属性只有style,如果只写 border: solid,其他属性会自动使用缺省值。
border缺省宽度是medium(大约3px-4px),缺省颜色是border里面的内容文字的颜色。
如果这些缺省值可以满足你的要求,你完全可以省略这两项属性。

6. 专门用于打印的CSS文档
<link type="text/css" rel="stylesheet" href="stylesheet.css" media="screen" />
<link type="text/css" rel="stylesheet" href="printstyle.css" media="print" />

7. 单行文字CSS中的内容垂直对齐
设置行高与内容块等高,如:line-height: 32px;

8. 让背景色能够垂直拉齐到底部
要解决这个问题似乎只能用一个取巧的办法,根据每列的宽度和背景色设置背景图片,让用户看上去似乎拉平了:
body{background: url(blue-image.gif) 0 0 repeat-y}

9. block / inline 属性
block元素的特性包括:
    总是另起一行开始显示
    height line-height top bottom margin属性可以被设置,width缺省值是100%
    这一类的HTML元素包括<div>, <p>, <h1>, <form>, <ul> 以及 <li>等。

inline元素的特性包括:
    直接跟在当前行的后面显示
    height line-height top bottom margin属性不能改变,width等于包含文字/图片的宽度,width不能改变
    这一类的HTML元素包括<span>, <a>, <label>, <input>, <img>, <strong> 以及 <em>等。

可以通过设置元素属性display: inline 或 display: block来改变元素的以上特性。

10. 设置页面的最小宽度
CSS语法中很有用的一个属性是 min-width,通过它可以设置任何元素的最小宽度。
但有个问题:IE浏览器无法为元素设置min-width,解决方法:
#container{
    min-width:600px;max-width:1200px;
    width:expression(document.body.clientWidth < 600? "600px" : document.body.clientWidth > 1200? "1200px" : "auto");
}
第一个属性是最小宽度定义的标准写法;
第二个属性则是只有IE能够理解的javascript表达式。

11. Text-transform 属性
其常见的可用值包括:text-transform: uppercase(大写)/lowercase(小写)/capitalize(首字母大写)。

12. IE中消失的文字和图片
IE有个很莫名其妙的Bug:有时候文字或者背景图片死活显示不出来。如果你全选整个页面,会发现那些内容实际上还在那里,或者重新刷新一下页面显示就正常了。
解决:
可以尝试给消失的元素加 position: relative 属性。
如果不行,再试着设置width属性。

13. 颜色的缩写
可以将 #ff0033 缩写成 #f03

14. 关闭输入法状态
使用户只能输入英文状态下的字符,类似输入密码:input{ime-mode:disabled;}

15.半透明
.cls {filter:alpha(opacity=50); opacity:0.5;}
 
2008年07月08日 星期二 16:47

<form name='myForm'>
<select name='mySelect'>
    <option value='1'>夸父</option>
    <option value='2'>女娲</option>
    <option value='3'>人造人</option>
</select>
</form>

<script>
objSelect = document.myForm.mySelect;

//获取表单索引
objSelect.selectedIndex

//删除下拉框内某项 (任选)
objSelect.options[objSelect.selectedIndex] = null;
objSelect.remove(objSelect.selectedIndex);


//显示下拉框的内容
objSelect.options[objSelect.selectedIndex].text;
objSelect.options[objSelect.selectedIndex].value;


//建立Option对象
var objOption = new Option(‘内容','value');
objSelect.options[objSelect.options.length] = objOption;

</script>

 
2008年06月25日 星期三 13:34
403错误: You don't have permission to access..
<Directory />
   …… (省略不关心内容)
    将 deny from all 修改为:allow from all
</Directory>

设置404错误的方法...
整站设置:
修改apache配置文件http.conf下的ErrorDocument
修改为 ErrorDocument 404 你希望它转向的地址(你自定义的出错页面)

单目录设置:
在http.conf中加入如下代码:
[Directory 目录路径]
ErrorDocument 404 你希望它转向的地址(你自定义的出错页面)
[/Directory]

允许/不允许 (显示) 网站索引目录..
<Directory />
# Options FollowSymLinks 不允许读网站目录
# Options Indexes FollowSymLinks 允许读网站目录
</Directory>

不断添加ing...
待续..
 
2008年06月06日 星期五 14:48
做WEB常用到的形状
边框和标题:像是页面主题
基本形状:默认的,画图基本都会用到
公共控件:WEB页面经常看到的元素(表单、滚动条、进度条、树菜单等等)
标注:非常不错的页面元素说明

不断添加ing...
待续..
 
2008年04月25日 星期五 10:09
SYMFONY对于没有主键的表,会默认加入一个“ID”列,这在查询时会报数据库错误,因为表里没有“ID”这个列,解决办法:

1、设计表结构时加入ID列,虽然它在关系表一点用途都没有!

2、设置选择列,不出现 SELECT ID...
Model语句改为(注:不要改map和om,因为生成代码时会被覆盖):
class BpTableNamePeer extends BaseBpTableNamePeer {
static public function addSelectColumns(Criteria $criteria) {
    $criteria->addSelectColumn(BpTableNamePeer::CHANNEL_ID);
    $criteria->addSelectColumn(BpTableNamePeer::PARENT_ID);
    $criteria->addSelectColumn(BpTableNamePeer::NAME_EN);
    $criteria->addSelectColumn(BpTableNamePeer::NAME_CN);
}
}

Action语句(一定要用 doSelectRS而不是doSelect):
$tResults = BpChannelConnectPeer::doSelectRS();
foreach($tResults as $tResult){
var_dump($tResult);
}
注:必须用 foreach 或 next 遍历数组

3、直接写SQL查询,参见前面的文章,在此不再赘述。
 
2008年03月11日 星期二 09:46
CREATE

1、Simple INSERT


$author = new Author();
$author->setFirstName("Jack");
$author->setLastName("London");
$author->save();



2、Related Row Insert

// 1) Create an Author (row of 'author' table)
$author = new Author();
$author->setFirstName("Leo");
$author->setLastName("Tolstoy");


// 2) Create a Publisher (row of 'publisher' table)
$pub = new Publisher();
$pub->setName("Viking Press");
// note: we don't save this yet


// 3) Create a Book (row of 'book' table)
$book = new Book();
$book->setTitle("War & Peace");
$book->setIsbn("0140444173");
$book->setPublisher($pub);
$book->setAuthor($author);

// saves all 3 objects!
$book->save();



RETRIEVE

Retrieving by Primary Key


// A) Single-Col PK
$firstBook = BookPeer::retrieveByPK(1);

// B) Getting Multiple Objects By PK
$selectedBooks = BookPeer::retrieveByPKs(array(1,2,3,4,5,6,7));

// C) Multi-Col PK
$myObject = MultiColPKExamplePeer::retrieveByPK(1,2);


Querying the Database

//Simple Criteria
$c = new Criteria();
$c->add(AuthorPeer::FIRST_NAME, "Karl");
$c->add(AuthorPeer::LAST_NAME, "Marx", Criteria::NOT_EQUAL);

$authors = AuthorPeer::doSelect($c);
//相当于
SELECT ... FROM author WHERE author.FIRST_NAME = 'Karl' AND author.LAST_NAME <> 'Marx';

$c = new Criteria();
$c->add(AuthorPeer::LAST_NAME, array("Tolstoy", "Dostoevsky", "Bakhtin"), Criteria::IN);
$authors = AuthorPeer::doSelect($c);
// $authors contains array of Author objects

//相当于
SELECT ... FROM author WHERE author.LAST_NAME IN ('Tolstoy', 'Dostoevsky', 'Bakhtin');


Logically Complex Criteria (AND / OR)


$c = new Criteria();
$cton1 = $c->getNewCriterion(AuthorPeer::FIRST_NAME, "Leo");
$cton2 = $c->getNewCriterion(AuthorPeer::LAST_NAME, array("Tolstoy", "Dostoevsky", "Bakhtin"), Criteria::IN);

// combine them
$cton1->addOr($cton2);
// add to Criteria
$c->add($cton1);
//相当于
SELECT ... FROM author WHERE (author.FIRST_NAME = 'Leo' OR author.LAST_NAME IN ('Tolstoy', 'Dostoevsky', 'Bakhtin'));

$c = new Criteria();
$cton1 = $c->getNewCriterion(AuthorPeer::FIRST_NAME, "Leo");
$cton2 = $c->getNewCriterion(AuthorPeer::FIRST_NAME, "Karl");
// combine them
$cton1->addOr($cton2);
// add to Criteria
$c->add($cton1);

//或者
$c = new Criteria();
$c->add(AuthorPeer::FIRST_NAME, "Leo");
$c->addOr(AuthorPeer::FIRST_NAME, "Karl");



直接使用SQL语句

$con = Propel::getConnection(DATABASE_NAME);
$sql = "SELECT books.* FROM books WHERE NOT EXISTS (SELECT id FROM review WHERE book_id = book.id)";
$stmt = $con->createStatement();
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_NUM);
$books = BookPeer::populateObjects($rs);




UPDATE

Single Table
// 1) Fetch an object by primary key
$myBook = BookPeer::retrieveByPK(1);
// 2) update the values & save() it.
$myBook ->setTitle("War & Peace");
$myBook->save();



Relation Tables
// 1) retrieve an Author
$author = AuthorPeer::retrieveByPK(1);
// 2) retrieve a Book
$book = BookPeer::retrieveByPK(1);
// 3) now blindly set $author as the author for $book!
$book->setAuthor($author);
$book->save();




DELETE


//Using Peer 以键删除
BookPeer::doDelete(1);

//以类对象删除
$book = BookPeer::retrieveByPK(1);
BookPeer::doDelete($book);


//Using Object (and now you must remember that you can no longer use the $book object)
$book = BookPeer::retrieveByPK(1);
$book->delete();
 
2008年03月03日 星期一 14:44
我已经按如下步骤配置成功,如在哪个步骤出现问题,希望能告之,谢谢!
联系方式:2050479@Gmail.com 或 QQ2050479@msn.com

首先,你已经安装好了 Apache 2.x + PHP 5.2.x + Mysql 5,那么继续:

A.解压 symfony-1.0.11 到 D:\symfony-1.0.11

B.建立工作目录 D:\project\bpcms

C.配置Apache虚拟目录
    注明:apache配置文件中(httpd.conf),去掉 Include conf/extra/httpd-vhosts.conf 前的 # 号,
    再编辑:httpd-vhosts.conf
    <VirtualHost *:80>
        ServerAdmin 2050479@gmail.com
        ServerName zhangyang
        Alias /sf "D:\symfony-1.0.11\data\web\sf"
        DocumentRoot "D:\project\bpcms\web"
        ErrorLog "logs/zhangyang-error.log"
        CustomLog "logs/zhangyang-access.log" common
    </VirtualHost>

D.设置环境变量
我的电脑(鼠标右击) > 系统属性 > 高级 > 系统变量 > 修改变量"Path" 的值:
在其后增加: D:\symfony-1.0.11\data\bin

E.设置PHP环境变量(PHP安装路径根据自己的环境决定)
用记事本打开:D:\symfony-1.0.11\data\bin\symfony.bat
修改 PHP_COMMAND 的值为 : D:\MyServer\PHP5.2.3\php.exe

F.创建DB : bpcms (utf8编码)

G.执行命令行 (运行cmd)
D:\project\bpcms>
        symfony init-project bpcms

H.配置项目参数
D:\project\bpcms\config\config.php 修改为:
<?php
$sf_symfony_lib_dir = 'D:\symfony-1.0.11\lib';
$sf_symfony_data_dir = 'D:\symfony-1.0.11\data';
date_default_timezone_set('Asia/Shanghai');


D:\project\bpcms\config\schema.yml修改为:
propel:
blog_article:
    _attributes: { phpName: Article }
    id:
    title:       varchar(255)
    content:     longvarchar
    created_at:
blog_comment:
    _attributes: { phpName: Comment }
    id:
    article_id:
    author:      varchar(255)
    content:     longvarchar
    created_at:


D:\project\bpcms\config\propel.ini 配置数据库参数
(注:连接MYSQL的帐号/密码/库,根据自己配置)
propel.targetPackage       = lib.model
propel.packageObjectModel = true
propel.project             = bpcms
propel.database            = mysql
propel.database.createUrl = mysql://bpcms:bpcms@localhost/
propel.database.url        = mysql://bpcms:bpcms@localhost/bpcms


D:\project\bpcms\config\databases.yml
all:
propel:
    class:          sfPropelDatabase
    param:
      dsn:          mysql://bpcms:bpcms@localhost/bpcms


G.执行命令行 (运行cmd)
D:\project\bpcms>
        symfony init-app cms
        symfony module cms say
        symfony propel-build-model
        symfony propel-build-sql
        symfony propel-insert-sql
        symfony app admin
        symfony propel-init-admin admin article Article

H.测试:
用记事本打开:C:\WINDOWS\system32\drivers\etc\hosts
添加一行:127.0.0.1      zhangyang

http://zhangyang/
http://zhangyang/cms_dev.php
http://zhangyang/cms_dev.php/say
http://zhangyang/admin_dev.php/article


关于YML,请注意缩进的写法,
关于Symfony 参数,可以命令行输入symfony回车,
更多请Google.. : )
 
2008年01月15日 星期二 04:52

优化PHP代码的40条建议
40 Tips for optimizing your php Code

来源:http://www.phpchina.com/bbs/viewthread.php?tid=48998
原文地址:http://reinholdweber.com/?p=3
英文版权归Reinhold Weber所有,中译文作者yangyang(aka davidkoree)。
双语版可用于非商业传播,但须注明英文版作者、版权信息,以及中译文作者。

1.If a method can be static, declare it static. Speed improvement is by a factor of 4.
如果一个方法可静态化,就对它做静态声明。速率可提升至4倍。

2.echo is faster than print.
echo 比 print 快。

3.Use echo's multiple parameters instead of string concatenation.
使用echo的多重参数(译注:指用逗号而不是句点)代替字符串连接。

4.Set the maxvalue for your for-loops before and not in the loop.
在执行for循环之前确定最大循环数,不要每循环一次都计算最大值。

5.Unset your variables to free memory, especially large arrays.
注销那些不用的变量尤其是大数组,以便释放内存。

6.Avoid magic like __get, __set, __autoload.
尽量避免使用__get,__set,__autoload。

7.require_once() is expensive.
require_once()代价昂贵。

8.Use full paths in includes and requires, less time spent on resolving the OS paths.
在包含文件时使用完整路径,解析操作系统路径所需的时间会更少。

9.If you need to find out the time when the script started executing, $_SERVER['REQUEST_TIME'] is preferred to time().
如果你想知道脚本开始执行(译注:即服务器端收到客户端请求)的时刻,使用$_SERVER['REQUEST_TIME']要好于time()。

10.See if you can use strncasecmp, strpbrk and stripos instead of regex.
检查是否能用strncasecmp,strpbrk,stripos函数代替正则表达式完成相同功能。

11.str_replace is faster than preg_replace, but strtr is faster than str_replace by a factor of 4.
str_replace函数比preg_replace函数快,但strtr函数的效率是str_replace函数的四倍。

12.If the function, such as string replacement function, accepts both arrays and single characters as arguments, and if your argument list is not too long, consider writing a few redundant replacement statements, passing one character at a time, instead of one line of code that accepts arrays as search and replace arguments.
如果一个字符串替换函数,可接受数组或字符作为参数,并且参数长度不太长,那么可以考虑额外写一段替换代码,使得每次传递参数是一个字符,而不是只写一行代码接受数组作为查询和替换的参数。

13.It's better to use select statements than multi if, else if, statements.
使用选择分支语句(译注:即switch case)好于使用多个if,else if语句。

14.Error suppression with @ is very slow.
用@屏蔽错误消息的做法非常低效。

15.Turn on apache's mod_deflate.
打开apache的mod_deflate模块。

16.Close your database connections when you're done with them.
数据库连接当使用完毕时应关掉。

17.$row['id'] is 7 times faster than $row[id].
$row['id']的效率是$row[id]的7倍。

18.Error messages are expensive.
错误消息代价昂贵。

19.Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time.
尽量不要在for循环中使用函数,比如for ($x=0; $x < count($array); $x)每循环一次都会调用count()函数。

20.Incrementing a local variable in a method is the fastest. Nearly the same as calling a local variable in a function.
在方法中递增局部变量,速度是最快的。几乎与在函数中调用局部变量的速度相当。

21.Incrementing a global variable is 2 times slow than a local var.
递增一个全局变量要比递增一个局部变量慢2倍。

22.Incrementing an object property (eg. $this->prop++) is 3 times slower than a local variable.
递增一个对象属性(如:$this->prop++)要比递增一个局部变量慢3倍。

23.Incrementing an undefined local variable is 9-10 times slower than a pre-initialized one.
递增一个未预定义的局部变量要比递增一个预定义的局部变量慢9至10倍。

24.Just declaring a global variable without using it in a function also slows things down (by about the same amount as incrementing a local var). PHP probably does a check to see if the global exists.
仅定义一个局部变量而没在函数中调用它,同样会减慢速度(其程度相当于递增一个局部变量)。PHP大概会检查看是否存在全局变量。

25.Method invocation appears to be independent of the number of methods defined in the class because I added 10 more methods to the test class (before and after the test method) with no change in performance.
方法调用看来与类中定义的方法的数量无关,因为我(在测试方法之前和之后都)添加了10个方法,但性能上没有变化。

26.Methods in derived classes run faster than ones defined in the base class.
派生类中的方法运行起来要快于在基类中定义的同样的方法。

27.A function call with one parameter and an empty function body takes about the same time as doing 7-8 $localvar++ operations. A similar method call is of course about 15 $localvar++ operations.
调用带有一个参数的空函数,其花费的时间相当于执行7至8次的局部变量递增操作。类似的方法调用所花费的时间接近于15次的局部变量递增操作。

28.Surrounding your string by ' instead of " will make things interpret a little faster since php looks for variables inside "…" but not inside '…'. Of course you can only do this when you don't need to have variables in the string.
用单引号代替双引号来包含字符串,这样做会更快一些。因为PHP会在双引号包围的字符串中搜寻变量,单引号则不会。当然,只有当你不需要在字符串中包含变量时才可以这么做。

29.When echoing strings it's faster to separate them by comma instead of dot. Note: This only works with echo, which is a function that can take several strings as arguments.
输出多个字符串时,用逗号代替句点来分隔字符串,速度更快。注意:只有echo能这么做,它是一种可以把多个字符串当作参数的“函数”(译注:PHP手册中说echo是语言结构,不是真正的函数,故把函数加上了双引号)。

30.A PHP script will be served at least 2-10 times slower than a static HTML page by Apache. Try to use more static HTML pages and fewer scripts.
Apache解析一个PHP脚本的时间要比解析一个静态HTML页面慢2至10倍。尽量多用静态HTML页面,少用脚本。

31.Your PHP scripts are recompiled every time unless the scripts are cached. Install a PHP caching product to typically increase performance by 25-100% by removing compile times.
除非脚本可以缓存,否则每次调用时都会重新编译一次。引入一套PHP缓存机制通常可以提升25%至100%的性能,以免除编译开销。

32.Cache as much as possible. Use memcached - memcached is a high-performance memory object caching system intended to speed up dynamic web applications by alleviating database load. OP code caches are useful so that your script does not have to be compiled on every request.
尽量做缓存,可使用memcached。memcached是一款高性能的内存对象缓存系统,可用来加速动态Web应用程序,减轻数据库负载。对运算码(OP code)的缓存很有用,使得脚本不必为每个请求做重新编译。

33.When working with strings and you need to check that the string is either of a certain length you'd understandably would want to use the strlen() function. This function is pretty quick since it's operation does not perform any calculation but merely return the already known length of a string available in the zval structure (internal C struct used to store variables in PHP). However because strlen() is a function it is still somewhat slow because the function call requires several operations such as lowercase & hashtable lookup followed by the execution of said function. In some instance you can improve the speed of your code by using an isset() trick.
当操作字符串并需要检验其长度是否满足某种要求时,你想当然地会使用strlen()函数。此函数执行起来相当快,因为它不做任何计算,只返回在zval结构(C的内置数据结构,用于存储PHP变量)中存储的已知字符串长度。但是,由于strlen()是函数,多多少少会有些慢,因为函数调用会经过诸多步骤,如字母小写化(译注:指函数名小写化,PHP不区分函数名大小写)、哈希查找,会跟随被调用的函数一起执行。在某些情况下,你可以使用isset()技巧加速执行你的代码。

Ex.(举例如下)
if (strlen($foo) < 5) { echo "Foo is too short"; }
vs.(与下面的技巧做比较)
if (!isset($foo{5})) { echo "Foo is too short"; }

Calling isset() happens to be faster then strlen() because unlike strlen(), isset() is a language construct and not a function meaning that it's execution does not require function lookups and lowercase. This means you have virtually no overhead on top of the actual code that determines the string's length.
调用isset()恰巧比strlen()快,因为与后者不同的是,isset()作为一种语言结构,意味着它的执行不需要函数查找和字母小写化。也就是说,实际上在检验字符串长度的顶层代码中你没有花太多开销。

34.When incrementing or decrementing the value of the variable $i++ happens to be a tad slower then ++$i. This is something PHP specific and does not apply to other languages, so don't go modifying your C or Java code thinking it'll suddenly become faster, it won't. ++$i happens to be faster in PHP because instead of 4 opcodes used for $i++ you only need 3. Post incrementation actually causes in the creation of a temporary var that is then incremented. While pre-incrementation increases the original value directly. This is one of the optimization that opcode optimized like Zend's PHP optimizer. It is still a good idea to keep in mind since not all opcode optimizers perform this optimization and there are plenty of ISPs and servers running without an opcode optimizer.
当执行变量$i的递增或递减时,$i++会比++$i慢一些。这种差异是PHP特有的,并不适用于其他语言,所以请不要修改你的C或Java代码并指望它们能立即变快,没用的。++$i更快是因为它只需要3条指令(opcodes),$i++则需要4条指令。后置递增实际上会产生一个临时变量,这个临时变量随后被递增。而前置递增直接在原值上递增。这是最优化处理的一种,正如Zend的PHP优化器所作的那样。牢记这个优化处理不失为一个好主意,因为并不是所有的指令优化器都会做同样的优化处理,并且存在大量没有装配指令优化器的互联网服务提供商(ISPs)和服务器。

35.Not everything has to be OOP, often it is too much overhead, each method and object call consumes a lot of memory.
并不是事必面向对象(OOP),面向对象往往开销很大,每个方法和对象调用都会消耗很多内存。

36.Do not implement every data structure as a class, arrays are useful, too.
并非要用类实现所有的数据结构,数组也很有用。

37.Don't split methods too much, think, which code you will really re-use.
不要把方法细分得过多,仔细想想你真正打算重用的是哪些代码?

38.You can always split the code of a method later, when needed.
当你需要时,你总能把代码分解成方法。

39.Make use of the countless predefined functions.
尽量采用大量的PHP内置函数。

40.If you have very time consuming functions in your code, consider writing them as C extensions.
如果在代码中存在大量耗时的函数,你可以考虑用C扩展的方式实现它们。

41.Profile your code. A profiler shows you, which parts of your code consumes how many time. The Xdebug debugger already contains a profiler. Profiling shows you the bottlenecks in overview.
评估检验(profile)你的代码。检验器会告诉你,代码的哪些部分消耗了多少时间。Xdebug调试器包含了检验程序,评估检验总体上可以显示出代码的瓶颈。

42.mod_gzip which is available as an Apache module compresses your data on the fly and can reduce the data to transfer up to 80%.
mod_zip可作为Apache模块,用来即时压缩你的数据,并可让数据传输量降低80%。

43.Excellent Article (http://phplens.com/lens/php-book/optimizing-debugging-php.php) about optimizing php by John Lim.
另一篇优化PHP的精彩文章,由John Lim撰写。

 
     
 
 
个人档案
 
 2050479
男, 26岁
北京 朝阳区 
加为好友
 
   
 
文章分类
 
 
 
Php(9)
 
Mysql(10)
 
Css(2)
 
Xml(0)
 
 
 
 
     
 
文章存档
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
     
 
留言板
 

本人帮你管理职院吧吧
 

图片小编怎么找到的我喔?怎么找我喔?
 

我想成为图片小编可以吗?
 

苏菲?
近来可好,怎么找到我的?
 

我是你弟妹,额- -~
 
     
 
最新评论
   
文章评论|照片评论


受益了, 呵呵!
 
 

我来沙发了,支持,狂顶!不错的文章!
 
 
     


©2008 Baidu