Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 383
TigerBear Avatar asked May 20 '14 00:05

TigerBear


People also ask

What is compile time and runtime in PHP?

Compile time is the period when the programming code (such as C#, Java, C, Python) is converted to the machine code (i.e. binary code). Runtime is the period of time when a program is running and generally occurs after compile time.

Is PHP runtime or compile time?

Basically, PHP is interpreted but PHP is compiled down to an intermediate bytecode that is then interpreted by the runtime Zend engine.

What is compile time?

In computer science, compile time (or compile-time) describes the time window during which a computer program is compiled. The term is used as an adjective to describe concepts related to the context of program compilation, as opposed to concepts related to the context of program execution (runtime).

What is compile time and execution time?

Compile time address binding is done before loading the program into memory. Execution time address binding is done at the time of program execution. Instructions are translated into absolute address. It helps in execution.


1 Answers

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.

like image 115
gview Avatar answered Oct 26 '22 19:10

gview