深入理解PHP原理之执行周期分析,深入理解php
深入理解PHP原理之执行周期分析,深入理解php
本文讲述了PHP原理之执行周期。分享给大家供大家参考,具体如下:
PHP的执行周期,从最初我们编写的PHP脚本->到最后脚本被执行->得到执行结果,这个过程,其实可以分为如下几个阶段:
首先,Zend Engine(ZE),调用词法分析 器(Lex生成的,源文件在 Zend/zend_language_sanner.l), 将我们要执行的PHP源文件,去掉空格 ,注释,分割成一个一个的token。
然后,ZE会将得到的token forward给语法分析 器(yacc生成, 源文件在 Zend/zend_language_parser.y),生成一个一个的opcode,opcode一般会以op array的形式存在,它是PHP执行的中间语言。
最后,ZE调用zend_executor来执行op array ,输出结果。(也就是将源文件转换成机器语言,然后在虚拟机上运行它。)
ZE是一个虚拟机,正是由于它的存在,所以才能使得我们写PHP脚本,完全不需要考虑所在的操作系统类型是什么,这才是PHP的可移植性的原因。ZE是一个CISC(复杂指令处理器),它支持150条指令(具体指令在 Zend/zend_vm_opcodes.h),包括从最简单的ZEND_ECHO(echo)到复杂的 ZEND_INCLUDE_OR_EVAL(include,require),所有我们编写的PHP都会最终被处理为这150条指令(op code)的序列,从而最终被执行。
PHP是一个脚本语言,也就是说,用户编写的PHP代码最终都是会被PHP解释器解释执行,所有编写的PHP代码,都会被翻译成PHP的虚拟机ZE的虚拟指令(OPCODES)来执行。
那我们的PHP脚本,最终被“翻译"成什么样的呢? 也就是说,op code长的什么样子呢? Opcode是一种PHP脚本编译后的中间语言。
在PECL中已经有这样的模块,利用由 Derick Rethans开发的VLD (Vulcan Logic Dissassembler)模块。你只要下载这个模块,并把他载入PHP中,就可以通过简单的设置,来得到脚本翻译的结果了。
VLD模块的安装以及应用:
[root@localhost software]# tar zxvf vld-0.9.1.tgz.gz [root@localhost vld-0.9.1]# /usr/local/php/bin/phpize [root@localhost vld-0.9.1]# ./configure --with-php-config=/usr/local/php/bin/php-config [root@localhost vld-0.9.1]# make install //不需要make
编辑php.ini文件并激活vld扩展。
实例:
创建一个文件,如:hello.php
<?php echo 'hello, world.'; ?>
执行:
[root@localhost html]# /usr/local/php/bin/php -dvld.active=1 hello.php Branch analysis from position: 0 Return found filename: /var/www/html/hello.php function name: (null) number of ops: 3 compiled vars: none line # op fetch ext return operands ------------------------------------------------------------------------------- 2 0 ECHO 'hello%2C+world.' 4 1 RETURN 1 2* ZEND_HANDLE_EXCEPTION hello, world.
看另一个:
[root@localhost html]# vi vld.php <?php $i = "This is a string"; //I am comments echo $i. ' that has been echoed on screen'; ?>
执行:
[root@localhost html]# /usr/local/php/bin/php -dvld.active=1 vld.php Branch analysis from position: 0 Return found filename: /var/www/html/vld.php function name: (null) number of ops: 5 compiled vars: !0 = $i line # op fetch ext return operands ------------------------------------------------------------------------------- 3 0 ASSIGN !0, 'This+is+a+string' 7 1 CONCAT ~1 !0, '+that+has+been+echoed+on+screen' 2 ECHO ~1 10 3 RETURN 1 4* ZEND_HANDLE_EXCEPTION This is a string that has been echoed on screen
注:ZEND_HANDLE_EXCEPTION 就是 Zend/zend_vm_opcodes.h 中第149条指令
compiled vars: !0 = $i 此处是获取变量名"i"的变量于!0(*zval)。
#0 将字符串"this+is+a+string"赋值(ASSIGN)给!0
#1 字符串连接
#2 显示
这些中间代码会被Zend VM(Zend虚拟机)直接执行。真正负责执行的函数是:zend_execute(zend_execute.h)。
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP数学运算技巧总结》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《PHP数组(Array)操作技巧大全》、《php排序算法总结》、《PHP常用遍历算法与技巧总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《php正则表达式用法总结》、《PHP运算与运算符用法总结》、《php字符串(string)用法总结》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The problem was found in the springboot project production session-out timeout. The problem is described below: In the test environment, the session-out was configured by changing the application.yaml. After setting different times to verify that the session-out configuration took effect, the expiration time was directly set to 8 hours for release. Arrived in production environment. However, I received feedback from customers at noon that the project expiration time was set to be short. If no operation is performed for half an hour, the session will expire and require repeated logins. Solve the problem of handling the development environment: the springboot project has built-in Tomcat, so the session-out configured in application.yaml in the project is effective. Production environment: Production environment release is

Session failure is usually caused by the session lifetime expiration or server shutdown. The solutions: 1. Extend the lifetime of the session; 2. Use persistent storage; 3. Use cookies; 4. Update the session asynchronously; 5. Use session management middleware.

Solution to the cross-domain problem of PHPSession In the development of front-end and back-end separation, cross-domain requests have become the norm. When dealing with cross-domain issues, we usually involve the use and management of sessions. However, due to browser origin policy restrictions, sessions cannot be shared by default across domains. In order to solve this problem, we need to use some techniques and methods to achieve cross-domain sharing of sessions. 1. The most common use of cookies to share sessions across domains

Solution to the problem that the php session disappears after refreshing: 1. Open the session through "session_start();"; 2. Write all public configurations in a php file; 3. The variable name cannot be the same as the array subscript; 4. In Just check the storage path of the session data in phpinfo and check whether the sessio in the file directory is saved successfully.

The default expiration time of session PHP is 1440 seconds, which is 24 minutes, which means that if the client does not refresh for more than 24 minutes, the current session will expire; if the user closes the browser, the session will end and the Session will no longer exist.

Problem: Today, we encountered a setting timeout problem in our project, and changes to SpringBoot2’s application.properties never took effect. Solution: The server.* properties are used to control the embedded container used by SpringBoot. SpringBoot will create an instance of the servlet container using one of the ServletWebServerFactory instances. These classes use server.* properties to configure the controlled servlet container (tomcat, jetty, etc.). When the application is deployed as a war file to a Tomcat instance, the server.* properties do not apply. They do not apply,

1. Implementing SMS login based on session 1.1 SMS login flow chart 1.2 Implementing sending SMS verification code Front-end request description: Description of request method POST request path /user/code request parameter phone (phone number) return value No back-end interface implementation: @Slf4j@ ServicepublicclassUserServiceImplextendsServiceImplimplementsIUserService{@OverridepublicResultsendCode(Stringphone,HttpSessionsession){//1. Verify mobile phone number if

JavaScriptCookies Using JavaScript cookies is the most effective way to remember and track preferences, purchases, commissions and other information. Information needed for a better visitor experience or website statistics. PHPCookieCookies are text files that are stored on client computers and retained for tracking purposes. PHP transparently supports HTTP cookies. How do JavaScript cookies work? Your server sends some data to your visitor's browser in the form of a cookie. Browsers can accept cookies. If present, it will be stored on the visitor's hard drive as a plain text record. Now, when a visitor reaches another page on the site
