首页 > 代码库 > php缓存相关

php缓存相关

在php运行期间,php引擎要对php源码进行处理,(词法分析,语法分析等)然后生成opcode。

然后再运行。在这个阶段可以把opcode缓存起来,当下次需要运行这段程序的时候,就避免了再次 进行词法分析,语法分析,直接拿opcode来用。

eAccelerator就是这样的程序。

 

用vld查看php的opcode:

http://pecl.php.net/package/vld/0.12.0/windows

在上面的地址下载vld,解压后 将 php_vld.dll,拷贝到ext目录下。

修改php.ini,增加“extension=php_vld.dll”;

要查看opcode,新建一个php脚本,cmd下执行

“E:\xampp\php>php -dvld.active=1 e:\htdocs\mytest\n.php”命令。

显示结果:

E:\xampp\php>php -dvld.active=1 e:\htdocs\mytest\n.phpFinding entry pointsBranch analysis from position: 0Jump found. Position 1 = 13, Position 2 = 6Branch analysis from position: 13Return foundBranch analysis from position: 6Jump found. Position 1 = 3Branch analysis from position: 3Jump found. Position 1 = 1Branch analysis from position: 1filename:       E:\htdocs\mytest\n.phpfunction name:  (null)number of ops:  14compiled vars:  !0 = $iline     # *  op                           fetch          ext  return  operands---------------------------------------------------------------------------------  30     0  >   ASSIGN                                                   !0, 0         1  >   IS_SMALLER                                       ~1      !0, 100         2    > JMPZNZ                                        6          ~1, ->13         3  >   POST_INC                                         ~2      !0         4      FREE                                                     ~2         5    > JMP                                                      ->1  31     6  >   CONCAT                                           ~3      ‘a‘, !0         7      FETCH_W                      local               $4      ~3         8      ASSIGN                                                   $4, !0  32     9      CONCAT                                           ~6      ‘a‘, !0        10      FETCH_R                      local               $7      ~6        11      ECHO                                                     $7  33    12    > JMP                                                      ->3  36    13  > > RETURN                                                   1branch: #  0; line:    30-   30; sop:     0; eop:     0; out1:   1branch: #  1; line:    30-   30; sop:     1; eop:     2; out1:  13; out2:   6branch: #  3; line:    30-   30; sop:     3; eop:     5; out1:   1branch: #  6; line:    31-   33; sop:     6; eop:    12; out1:   3branch: # 13; line:    36-   36; sop:    13; eop:    13path #1: 0, 1, 13,path #2: 0, 1, 6, 3, 1, 13,0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899

安装eAccelerator:

下载:http://www.sitebuddy.com/php/accelerators/eaccelerator-windows-binaries

下载下来的文件解压后,将dll文件,贝到ext下

修改php.ini,开启

    [eAccelerator]    zend_extension_ts="C:/php/ext/eaccelerator.dll"       //路径根据实际情况而定    eaccelerator.shm_size="32"       //根据系统内存来定,默认16M,可以改成64M    eaccelerator.cache_dir="C:/php/temp"     //前面创建的缓冲文件夹    eaccelerator.enable="1"    eaccelerator.optimizer="1"    eaccelerator.check_mtime="1"    eaccelerator.debug="0"    eaccelerator.filter=""    eaccelerator.shm_max="0"    eaccelerator.shm_ttl="0"    eaccelerator.shm_prune_period="0"    eaccelerator.shm_only="0"    eaccelerator.compress="1"    eaccelerator.compress_level="9"

配置redis:

下载http://www.redis.cn/download.html

解压后有两个dll文件,全部拷贝到ext目录下。[我拷贝到ext,还提示找不到。最后拷贝到php.exe目录下才不再报错]。

修改php.ini

添加

"extension=php_igbinary.dll

 extension=php_vld.dll"

重启apache,phpinfo();可以查看是否启动。

 

测试redis:

$redis = new Redis();  $redis->connect("192.168.0.110","6379");  //php客户端设置的ip及端口  //存储一个 值  $redis->set("say","Hello World");  echo $redis->get("say");     //应输出Hello World    //存储多个值  $array = array(‘first_key‘=>‘first_val‘,            ‘second_key‘=>‘second_val‘,            ‘third_key‘=>‘third_val‘);  $array_get = array(‘first_key‘,‘second_key‘,‘third_key‘);  $redis->mset($array);  var_dump($redis->mget($array_get));