Is PHP code interpreted or compiled ?
Moderator: General Moderators
-
syamswaroop
- Forum Newbie
- Posts: 19
- Joined: Fri May 01, 2009 1:31 am
Is PHP code interpreted or compiled ?
hi all,
Iam having a basic doubt that is whether a PHP file is interpreted or compiled ?
and what exactly is preprocessor?
Iam having a basic doubt that is whether a PHP file is interpreted or compiled ?
and what exactly is preprocessor?
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Is PHP code interpreted or compiled ?
PHP is interpreted. Preprocessor, as in Hypertext Preprocessor, means that PHP is run server side and is processed before the resultant HTML is sent to the client browser.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Is PHP code interpreted or compiled ?
In fact PHP is compiled to bytecode which is executed by zend virtual machine.AbraCadaver wrote:PHP is interpreted.
Re: Is PHP code interpreted or compiled ?
PHP is interpreted to bytecode.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Is PHP code interpreted or compiled ?
Exactly.Jenk wrote:PHP is interpreted to bytecode.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Is PHP code interpreted or compiled ?
If you wish to dive into semantics then please define both terms: 'interpreted' and 'compiled'. I'd argue that if bytecode could be stored and reused later directly (without recompilation) it merits calling it 'compiled'.Jenk wrote:PHP is interpreted to bytecode.
Re: Is PHP code interpreted or compiled ?
As far as I understand it, compilation is to machine code, interpretation is to bytecode which is an intermediary step before compilation.
Re: Is PHP code interpreted or compiled ?
Unless you specifically implement caching, PHP doesn't do it. Every time a script (file ending with .php or other configured extension) is called, it is parsed and interpreted. There isn't a "build" process for PHP.Weirdan wrote:If you wish to dive into semantics then please define both terms: 'interpreted' and 'compiled'. I'd argue that if bytecode could be stored and reused later directly (without recompilation) it merits calling it 'compiled'.Jenk wrote:PHP is interpreted to bytecode.
Re: Is PHP code interpreted or compiled ?
Yes you're right.pytrin wrote:As far as I understand it, compilation is to machine code, interpretation is to bytecode which is an intermediary step before compilation.
A comparison would be Java, this is also interpreted into byte code which is then compiled by the Java Virtual Machine into machine code for a particular platform.
PHP certainly isn't compiled.
Re: Is PHP code interpreted or compiled ?
By my definition compiler is a program that translates from one machine language to some another. The kind of target language is irrelevant, be that machine code, jvm bytecode or C++ (as in HipHop). The difference between interpreter and compiler is that interpreter output cannot be stored for later reuse (due to the reliance on the internal interpreter state for example). Also interpreter would not even attempt to interpret a chunk of code until it needs to execute it.pytrin wrote:As far as I understand it, compilation is to machine code, interpretation is to bytecode which is an intermediary step before compilation.
The problem with the definition of compiler as a program that produces machine code is that many modern CPUs do not execute this code directly but *interpret* it into the set of μops.
Re: Is PHP code interpreted or compiled ?
As I said, that is the official definition I'm aware of. I understand this is mostly semantics, but as programmers we have a habit of being very detail oriented and so came about this discussion 
The CPU is a part of the machine (ie, hardware), so any set of instructions the CPU can read is effectively machine code. In fact, that is the very definition of machine code - http://en.wikipedia.org/wiki/Machine_code (this article goes to great care to differentiate bytecode and machine code)
The CPU is a part of the machine (ie, hardware), so any set of instructions the CPU can read is effectively machine code. In fact, that is the very definition of machine code - http://en.wikipedia.org/wiki/Machine_code (this article goes to great care to differentiate bytecode and machine code)
Re: Is PHP code interpreted or compiled ?
Modern day CPUs contain microcode/microprograms known as opcodes... I think? Rather than just receiving machine code instructions.
Haven't looked at this low level stuff in a while.
Haven't looked at this low level stuff in a while.
Re: Is PHP code interpreted or compiled ?
The definition used to depict the difference between an interpreted language, such as PHP, and a compiled language, such as C, is that you compile C once, and run it many times. PHP is compiled (interpreted) every time it is run.Weirdan wrote:By my definition compiler is a program that translates from one machine language to some another. The kind of target language is irrelevant, be that machine code, jvm bytecode or C++ (as in HipHop). The difference between interpreter and compiler is that interpreter output cannot be stored for later reuse (due to the reliance on the internal interpreter state for example). Also interpreter would not even attempt to interpret a chunk of code until it needs to execute it.pytrin wrote:As far as I understand it, compilation is to machine code, interpretation is to bytecode which is an intermediary step before compilation.
The problem with the definition of compiler as a program that produces machine code is that many modern CPUs do not execute this code directly but *interpret* it into the set of μops.
Re: Is PHP code interpreted or compiled ?
That's the dividing line I've always used. "Compiled" converts the initial language into an intermediate language - once. That intermediate file is then run multiple times. "Interpreted" converts the initial language into an intermediate language each time the program is run.Jenk wrote:The definition used to depict the difference between an interpreted language, such as PHP, and a compiled language, such as C, is that you compile C once, and run it many times. PHP is compiled (interpreted) every time it is run.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Is PHP code interpreted or compiled ?
pickle wrote:That's the dividing line I've always used. "Compiled" converts the initial language into an intermediate language - once. That intermediate file is then run multiple times. "Interpreted" converts the initial language into an intermediate language each time the program is run.
Not necessarily. With opcode cache source code is compiled to bytecode once and is run many times. With bcompiler extension you can store this bytecode to disk and run it later (even on different machine).Jenk wrote:The definition used to depict the difference between an interpreted language, such as PHP, and a compiled language, such as C, is that you compile C once, and run it many times. PHP is compiled (interpreted) every time it is run.
On the other hand nothing prevents you from writing an interpreter for C (and I'm sure such interpreters exist).