PHP
10/02 5
PHP的执行速度往往不是问题最大的地方,应该好好分析系统的各个方面,找到元凶。工具方面,他推荐用Yahoo的YSlow和Google的Page Speed分析前端的问题,再用Valgrind的Callgrind分析低层的后端性能,用XDebug分析用户空间PHP的性能。此外,他还顺带手指出了读写网前端的性能问题。
Tags:
09/12 28
<?php
//循环删除目录和文件函数
function delDirAndFile( $dirName )
{
if ( $handle = opendir( "$dirName" ) ) {
   while ( false !== ( $item = readdir( $handle ) ) ) {
   if ( $item != "." && $item != ".." ) {
   if ( is_dir( "$dirName/$item" ) ) {
   delDirAndFile( "$dirName/$item" );
   } else {
   if( unlink( "$dirName/$item" ) )echo "成功删除文件: $dirName/$item<br />\n";
   }
   }
   }
   closedir( $handle );
   if( rmdir( $dirName ) )echo "成功删除目录: $dirName<br />\n";
}
}
?>


<?php
//循环目录下的所有文件
function delFileUnderDir( $dirName="../Smarty/templates/templates_c" )
{
if ( $handle = opendir( "$dirName" ) ) {
   while ( false !== ( $item = readdir( $handle ) ) ) {
   if ( $item != "." && $item != ".." ) {
   if ( is_dir( "$dirName/$item" ) ) {
         delFileUnderDir( "$dirName/$item" );
   } else {
   if( unlink( "$dirName/$item" ) )echo "成功删除文件: $dirName/$item<br />\n";
   }
   }
   }
   closedir( $handle );
}
}

?>
Tags:
09/12 22
作者:老王

前提条件是你的系统已经安装好了apache和php,并且要有一份对应的php源代码,这些都不是难事。

-----------------------------------------------------------------------------------------------

进入php源代码目录,然后看看操作过程(这里假设我们要做一个名为test的扩展):

cd ./ext
./ext_skel --extname=test
cd ./test
vi config.m4

这里要对config.m4文件做一些修改:

dnl PHP_ARG_ENABLE(test, whether to enable test support,
dnl Make sure that the comment is aligned:
dnl [  --enable-test           Enable test support])

去掉上面三行的dnl,使之变为

PHP_ARG_ENABLE(test, whether to enable test support,
Make sure that the comment is aligned:
[  --enable-test           Enable test support])

dnl在这里是起到注释的作用,当然你也可以去掉下面三句前面的dnl

dnl PHP_ARG_WITH(test, for test support,
dnl Make sure that the comment is aligned:
dnl [  --with-test             Include test support])

这中间的区别就在于编译时是使用enable-test还是with-test,前者意味着不需要第三方库,后者正好相反,这里我们选择enable-test方式。

vi test.c

我们还可以通过修改test.c文件来增加或者的功能,这里我们是演示目的,就不修改这个文件了。

/usr/local/bin/phpize

执行这一步的目的是根据config.m4文件的内容生成configure文件

./configure --enable-test

make

这时,在./ext/test/modules目录就应该已经生成了test.so扩展模块了,怎么样,很简单吧。

make install

会自动把生成的test.so模块拷贝到php认为正确的扩展目录,我测试的时候此目录为 

/usr/local/lib/php/extensions/no-debug-non-zts-20060613/

no-debug-non-zts-20060613部分可能有差异,具体依赖与php的版本和编译选项。

如果你不详把扩展放在上面所示的目录中,可以

vi /usr/local/lib/php.ini

修改extension_dir选项为你的扩展目录名,并把test.so复制到此目录中

然后执行扩展目录中的test.php文件(此文件是自动生成的)

/usr/local/bin/php -f test.php

会发现如下字样:

Functions available in the test extension:
confirm_test_compiled

Congratulations! You have successfully modified ext/test/config.m4. Module test is now compiled into PHP.

----------------------------------------------------------------------------------------------

test.php文件中使用dl函数来动态加载test.so扩展,如果你想让php自动加载此扩展,只要进行如下操作即可:

vi /usr/local/lib/php.ini 加入extension=test.so

/usr/local/apache2/bin/apachectl restart

此时,如果你浏览phpinfo(),会发现test相应的扩展信息。

如果你使用命令行,那么通过下面命令也能看到:/usr/local/bin/php -m

----------------------------------------------------------------------------------------------

我们编写的test扩展成功了,当然,目前它还没有任何有用的功能,呵呵。
Tags:
09/12 22
sudo gedit sudo gedit ~/.vimrc   (就是它能让VIM穿衣服)

" 配置文件开始
" 将以下文本复制到你编辑的这个文件里面
" 项目: gvim 配置文件
" 作者: yonsan(StMadMan)
" 如果你的电脑中没有VIM请尝试安装: sudo apt-get install vim-gtk

" 使用 torte 的配色方案,如果你不喜欢这个方案
" 请依次点开VIM工具栏:编辑-配色方案-
" 选择你喜欢的方案然后把方案名写在下面
color torte
" 设置用于GUI图形用户界面的字体列表。
" 最后的选项是字体大小,如果你的字体的名字是由多个单词组成的请依次用"\"隔开
set guifont=Bitstream\Vera\Sans\Mono\ 11
''
set nocompatible
" 设定文件浏览器目录为当前目录
set bsdir=buffer
set autochdir
" 设置编码
set enc=utf-8
" 设置文件编码
set fenc=utf-8
" 设置文件编码检测类型及支持格式
set fencs=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
" 指定菜单语言
set langmenu=zh_CN.UTF-8
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
" 设置php语法高亮度
syntax enable
source $VIMRUNTIME/syntax/php.vim
"显示行号
set nu!
" 查找结果高亮度显示
set hlsearch
" tab宽度
set tabstop=4
set cindent shiftwidth=4
set autoindent shiftwidth=4
" 单行注释
set comments=://
" 段落注释
set comments=s1:/*,mb:*,ex0:/
" 增强检索功能
set tags=./tags,./../tags,./**/tags
" 键盘操作
map gk
map gj
" 命令行高度
set cmdheight=1
" 中文帮助
if version > 603
set helplang=cn
endi
" 配置文件结束
Tags:
09/10 30
GLAMMP
------------
Gearman+Linux+Apache+MySQL+MMemcached+PHP
09/10 14
nl2br();// \n to

addslashes(); stripslashes();//对数据库操作时,转义特殊字符

chop();//除去字符串右边空格
trim();//除去字符串中所有空格
ltrim();//除去字符串左边空格

htmlspecialchars();//转换'$','"','<','>'为相应的html实体
htmlentities();//转换所有html标记为相应的html实体

array explode(string separator, string str);//分割字符串
string implode(string separator, array arr);//连接字符串

strtoupper(); strtolower();//转换大小写
ucfirst();//只转换第一个字符为大写
ucwords();//转换每个words的第一个字母为大写
Tags:
09/10 13
1.如果一个方法可静态化,就对它做静态声明。速率可提升至4倍。

2.echo 比 print 快。

3.使用echo的多重参数(译注:指用逗号而不是句点)代替字符串连接。

4.在执行for循环之前确定最大循环数,不要每循环一次都计算最大值。

5.注销那些不用的变量尤其是大数组,以便释放内存。

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

....
Tags:
09/08 18
几个实用的例子。。。收录一下。
Tags: ,
分页: 1/4 第一页 1 2 3 4 下页 最后页 [ 显示模式: 摘要 | 列表 ]