>백엔드 개발 >PHP 튜토리얼 > 利用PHP扩张vld查看PHP opcode

利用PHP扩张vld查看PHP opcode

WBOY
WBOY원래의
2016-06-13 12:52:53895검색

利用PHP扩展vld查看PHP opcode

  作者:zhanhailiang 日期:2013-03-04

首先下载最新版vld扩展:

~/public_html/php-5.3.13/ext> wget http://pecl.php.net/get/vld-0.11.2.tgz
~/public_html/php-5.3.13/ext> tar zxvf vld-0.11.2.tgz 
~/public_html/php-5.3.13/ext> cd vld-0.11.2/

接下来编译安装vld扩展:

~/public_html/php-5.3.13/ext/vld-0.11.2> phpize 
~/public_html/php-5.3.13/ext/vld-0.11.2> ./configure --with-php-config=/usr/local/services/php/bin/php-config --enable-vld
~/public_html/php-5.3.13/ext/vld-0.11.2> make
~/public_html/php-5.3.13/ext/vld-0.11.2> sudo make install
Installing shared extensions:     /usr/local/services/php/lib/php/extensions/no-debug-non-zts-20090626/

最后将生成的vld.so复制到extension_dir目录下:

~/public_html/php-5.3.13/ext/vld-0.11.2> cd /usr/local/services/php/lib/php/extensions/no-debug-non-zts-20090626/
/usr/local/services/php/lib/php/extensions/no-debug-non-zts-20090626> sudo cp vld.so /usr/local/services/php/extensions/

然后修改php.ini文件,添加如下配置:

<span class="re1" style="color:rgb(0,0,255)">extension</span><span class="sy0" style="color:rgb(102,204,102)">=</span><span class="re2" style="color:rgb(0,0,255)">vld.so</span>

接下来创建test.php文件:

<span class="kw2" style="color:rgb(0,0,0); font-weight:bold"><?php</span>
 
<span class="re0" style="color:rgb(0,0,255)">$a</span> <span class="sy0" style="color:rgb(102,204,102)">=</span> <span class="st0" style="color:rgb(255,0,0)">"hello world"</span><span class="sy0" style="color:rgb(102,204,102)">;</span>
 
<span class="kw1" style="color:rgb(177,177,0)">echo</span> <span class="re0" style="color:rgb(0,0,255)">$a</span> <span class="sy0" style="color:rgb(102,204,102)">.</span> PHP_EOL<span class="sy0" style="color:rgb(102,204,102)">;</span>

使用cli来执行,查看生成的opcode:

~/public_html> php -dvld.active=1 test.php 
Finding entry points
Branch analysis from position: 0
Return found
filename:       /home/zhanhailiang/public_html/test.php
function name:  (null)
number of ops:  4
compiled vars:  !0 = $a
line     # *  op                           fetch          ext  return  operands
---------------------------------------------
   3     0  >   ASSIGN                                                   !0, 'hello&#43;world'
   5     1      CONCAT                                           ~1      !0, '%0A'
         2      ECHO                                                     ~1
   6     3    > RETURN                                                   1
 
branch: #  0; line:     3-    6; sop:     0; eop:     3
path #1: 0, 
hello world
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.