PHP 脚本到底是如何执行的?

发布于 2024-08-31 03:30:27 字数 188 浏览 11 评论 0原文

我只是在想“PHP 脚本究竟是如何执行的?”我认为它首先被解析语法错误等,然后解释和执行。

然而,我不知道为什么我相信这是正确的。我可能错了。

那么,PHP 文件到底是如何解释和执行的呢?这涉及到哪些阶段?包含的文件如何适合脚本的解析?

这只是为了帮助我理解它。我很感兴趣,但无法通过 Google 找到好的答案。

I was just thinking to myself "How exactly is a PHP script executed?" I thought it was parsed first for syntax errors etc, and then interpreted and executed.

However, I don't know why I believe that is correct. I'm probably wrong.

So, how exactly is a PHP file interpreted and executed? What stages does this involve? How do included files fit into the parsing of the script?

This is just to help me get my head around it. I'm interested and can not find a good answer with Google.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌上芳菲 2024-09-07 03:30:27

PHP 从 PHP 4.0 开始就是一种编译语言

什么是编译器的概念似乎是一个引起极大混乱的主题。有些人认为编译器是一种将一种语言的源代码转换为可执行程序的程序。编译器的定义实际上比这更广泛。

编译器是将源代码转换为代码的另一种表示形式的程序。目标表示通常是机器代码,但它也可能是另一种语言甚至同一种语言的源代码。

PHP 于 2000 年成为编译语言,当时 PHP 4 首次发布。在版本 3 之前,PHP 源代码由 PHP 解释器立即解析并执行。

PHP 4 引入了Zend 引擎。该引擎将 PHP 代码的处理分为几个阶段。第一阶段解析 PHP 源代码并生成 PHP 代码的二进制表示形式,称为 Zend 操作码。操作码是类似于 Java 字节码的指令集。这些操作码存储在内存中。 Zend 引擎处理的第二阶段包括执行生成的操作码。

更多信息请访问 http://www.phpclasses.org/blog/post/117 -PHP-compiler-performance.html

PHP is a compiled language since PHP 4.0

The idea of what is a compiler seems to be a subject that causes great confusion. Some people assume that a compiler is a program that converts source code in one language into an executable program. The definition of what is a compiler is actually broader than that.

A compiler is a program that transforms source code into another representation of the code. The target representation is often machine code, but it may as well be source code in another language or even in the same language.

PHP became a compiled language in the year 2000, when PHP 4 was released for the first time. Until version 3, PHP source code was parsed and executed right away by the PHP interpreter.

PHP 4 introduced the the Zend engine. This engine splits the processing of PHP code into several phases. The first phase parses PHP source code and generates a binary representation of the PHP code known as Zend opcodes. Opcodes are sets of instructions similar to Java bytecodes. These opcodes are stored in memory. The second phase of Zend engine processing consists in executing the generated opcodes.

Form more information go to http://www.phpclasses.org/blog/post/117-PHP-compiler-performance.html

浪推晚风 2024-09-07 03:30:27

基本上,每次加载 PHP 脚本时,都会经过两个步骤:

  • 解析 PHP 源代码,并将其转换为所谓的操作码。
    • 类似于 JAVA 的字节码
    • 如果您想了解这些内容,可以使用VLD 扩展
  • 然后,执行这些操作码

这些来自 Sebastian Bergmann 的幻灯片,在 Slideshare 上,可能会帮助您更好地理解该过程:PHP 编译器内部

Basically, each time a PHP script is loaded, it goes by two steps :

  • The PHP source code is parsed, and converted to what's called opcodes
    • Kind of an equivalent of JAVA's bytecode
    • If you want to see what those look like, you can use the VLD extension
  • Then, those opcode are executed

These slides from Sebastian Bergmann, on slideshare, might help you understand that process a bit better : PHP Compiler Internals

无尽的现实 2024-09-07 03:30:27

这里也是所有解析器标记的列表。

Here is also a list of all the parser tokens.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文