In PHP, what is meant by compile-time and run-time? [duplicate]

独自空忆成欢 提交于 2019-11-30 00:31:00

问题


PHP is an interpreted language, not compiled. Yet I have come across a book that mentions stuff happening in PHP at compile time, and the PHP manual states that declaring a const happens at compile-time. How is the term compile-time used in relation to PHP since PHP isn't compiled?

If it is just meant as "when the script is read and translated into the interpreters subroutines", then what is the difference between the terms compile-time and run-time?


回答1:


PHP source code goes through a step where it is compiled into PHP Opcode. This idea has been implemented in a variety of platforms, most notably with Java. Theoretically, by having a separate "virtual machine" runtime to run the Opcodes, the language designers are able to separate the language from portability issues.

You can find a list of these Opcodes in the manual

In a typical PHP environment with no opcode caching, the compilation step and the "run-time" step are indistinguishable, however, when you introduce an "accelerator/opscode cache" like APC or the Zend Platform product, you can see that these are separate steps in the process.

Once a script has been compiled into PHP Opscodes, it can be run from cache without having to be re-compiled from source, which is where these accelerators can greatly improve performance.

If you focus in on the "runtime" aspect of PHP you see the "Interpreted" nature of PHP, as it requires a runtime environment, when compared to a compiled/linked language like c/c++ that runs as a native operating system program.

In the case of PHP, the php program is the native operating system program (or native as a module of a native OS web server).

Not unlike the way Java runs inside of the "Java Virtual Machine (JVM)" PHP's scripts are running inside PHP and thus don't contain the specifics of how the operations are going to be natively performed by the OS.



来源:https://stackoverflow.com/questions/23749279/in-php-what-is-meant-by-compile-time-and-run-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!