Login   Register  
PHP Classes
elePHPant
Icontem

some corrections

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PHP Classes blog  >  Top 10 Wrong Ideas Ab...  >  All threads  >  some corrections  >  (Un) Subscribe thread alerts  
Subject:some corrections
Summary:PHP is not compiled
Messages:2
Author:Benjamin Dubois
Date:2011-08-18 18:25:29
Update:2011-08-19 04:46:04
 

  1. some corrections   Reply  
Picture of Benjamin Dubois
Benjamin Dubois
2011-08-18 19:24:28
Hi !

As far as I remember, PHP but also Java and C# (and many others) are all interpreted languages : they never produce a native executable for the platform they run on, but they produce an intermediate code (opcode for php, bytecode for java and common intermediate language for c#) which is interpreted by a native application (the JVM for java, the runtime for C# and the zend engine for PHP). That is what makes these 3 languages (and probably others) cross plaform without compilation.The main difference btween PHP and the 2 others is that PHP recompiles it's source on every request by default.

A compiled language uses a compiler in order to produce a binary file, directly executable on the host platform without any runtime environnement/ virtual machine.

More info here : http://en.wikipedia.org/wiki/Interpreted_language

  2. Re: some corrections   Reply  
Picture of Manuel Lemos
Manuel Lemos
2011-08-19 04:46:04 - In reply to message 1 from Benjamin Dubois
No, I do not agree. PHP is really compiled before being executed. The result of a compilation is binary code by the Zend engine. Here is is the main compiler file:

http://svn.php.net/viewvc/php/php-src/trunk/Zend/zend_compil ...

Until PHP 3, the PHP scripts were interpreted and executed at the same time. This means that if you had a syntax error in a PHP script, the error would only be spotted when the PHP interpreter attempted to run the line with the error.

Since PHP 4, the Zend Engine compiles the PHP code first before executing, as explained in the article. So, if you have a syntax error, it is spotted before the code is executed.

The fact that the actual execution of the compiled PHP code is done by a virtual machine, does not invalidate the fact that PHP code is compiled into binary code.

If it is important for you to compile PHP code into native machine code, there are extensions for that, besides mention Facebook HipHop for PHP compiler.

http://pecl.php.net/package/llvm

The fact is there is is not great interest on this because the performance gains for real world PHP applications are neglectable.

Other than that, if you use a caching extension (and most busy sites do), PHP does not recompile the original source code on every request, unless the source code is changed. That is actually an advantage of PHP because you do not have to be bothered with were the intermediate compiler output results go. It just stays in the shared memory for top loading and executing speed.