vld扩展的使用(该扩展可以查看PHP编译后的opcode)
PHP代码
<?php echo "Hello, pikaqiu!\n";
opcode查看
[root@iZ28mhfkaunZ bin]# ./php -dvld.active=1 /www/img/vld.php Finding entry points Branch analysis from position: 0 Jump found. Position 1 = -2 filename: /www/img/vld.php function name: (null) number of ops: 2 compiled vars: none line #* E I O op fetch ext return operands ------------------------------------------------------------------------------------- 2 0 E > ECHO 'Hello%2C+pikaqiu%21%0A' 1 > RETURN 1 branch: # 0; line: 2- 2; sop: 0; eop: 1; out1: -2 path #1: 0, Hello, pikaqiu!
很多编程语言都使用lex/yacc或他们的变体(flex/bison)来作为语言的词法语法分析生成器,
比如PHP、Ruby、Python以及MySQL的SQL语言实现。Lex和Yacc是Unix下的两个文本处理工具, 主要用于编写编译器, 也可以做其他用途。------Lex(词法分析生成器:A Lexical Analyzer Generator);Yacc(Yet Another Compiler-Compiler);
词法规则文件一般以.l作为扩展名;PHP以前使用的词法分析器是flex,后来PHP的词法解析改为使用re2c, $PHP_SRC/Zend/zend_language_scanner.l 文件是re2c的规则文件, 所以如果修改该规则文件需要安装re2c才能重新编译。
源码包中run-tests.php测试脚本的使用
[root@iZ28mhfkaunZ bin]# export TEST_PHP_EXECUTABLE=/usr/local/web/fastphp/bin/php [root@iZ28mhfkaunZ bin]# ./php /root/tipi/php-src/run-tests.php /root/tipi/php-src/tests/run-test/test001.phpt ===================================================================== PHP : /usr/local/web/fastphp/bin/php PHP_SAPI : cli PHP_VERSION : 5.6.6 ZEND_VERSION: 2.6.0 PHP_OS : Linux - Linux iZ28mhfkaunZ 3.10.0-123.9.3.el7.x86_64 #1 SMP Thu Nov 6 15:06:03 UTC 2014 x86_64 INI actual : /usr/local/web/fastphp/lib/php.ini More .INIs : CWD : /usr/local/web/fastphp/bin Extra dirs : VALGRIND : Not used ===================================================================== Running selected tests. PASS EXPECT [/root/tipi/php-src/tests/run-test/test001.phpt] ===================================================================== Number of tests : 1 1 Tests skipped : 0 ( 0.0%) -------- Tests warned : 0 ( 0.0%) ( 0.0%) Tests failed : 0 ( 0.0%) ( 0.0%) Expected fail : 0 ( 0.0%) ( 0.0%) Tests passed : 1 (100.0%) (100.0%) --------------------------------------------------------------------- Time taken : 0 seconds =====================================================================
1