PHP compile time vs run time. Understanding the difference

PHP makes two passes (by default) anytime it runs a file:

Pass #1 parses the file and builds what is called operational (or machine) code. This is the raw binary format your computer will actually run and it is not human readable. In other languages (like C++, etc) this is called compiling. You can cache this step using various systems like Opcache, which saves you the overhead of compiling this every time.

Syntax errors come from this portion of the execution.

At this point, the data coming from the web browser (or from any other source) is utterly irrelevant.

Then the code is executed with the data you supply (in Phase #2).

When you have opcode cached by Opcache, the first step can be skipped  because the structure of the code is exactly the same.

Pass #2 executes the operational code from Pass #1. This is what is commonly called „run time“, because your computer is actually executing the instructions.

Run-time errors (like exhausting memory, abnormal termination, etc…) come from this level. These are considerably less common than syntax errors, however.

Вашият коментар

Вашият имейл адрес няма да бъде публикуван. Задължителните полета са отбелязани с *