10/05 10
转载一篇 PHP 优化的一些小技巧。
Tags:
10/04 15
开发PHP扩展对于普通程序员来讲可能一直是一件很神秘的工作,其实,只要你对C语言熟悉,了解了开发PHP扩展的步骤和规则,开发PHP扩展也是一件很普通的工作。。。
Tags:
10/04 9
在php中,对于文件的读取时,最快捷的方式莫过于使用一些诸如file、file_get_contents之类的函数,简简单单的几行代码就能很漂亮的完成我们所需要的功能。但当所操作的文件是一个比较大的文件时,这些函数可能就显的力不从心, 下面将从一个需求入手来说明对于读取大文件时,常用的操作方法。 ....
Tags:
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  


" 使用 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
分页: 2/5 第一页 上页 1 2 3 4 5 下页 最后页 [ 显示模式: 摘要 | 列表 ]