Is PHP Compiled or Interpreted

Is PHP compiled or interpreted?

A compiled code can be executed directly by the computer's CPU. That is, the executable code is specified in the CPU's native language.

The code of interpreted languages must be translated at run-time from any format to CPU machine instructions. This translation is done by an interpreter.

It would not be proper to say that a language is interpreted or compiled, because interpretation and compilation are both properties of the implementation of that particular language and not a property of the language as such. So, any language can be compiled or interpreted — it just depends on what the particular implementation that you are using does.

The most widely used PHP implementation is powered by the Zend Engine and is known simply as PHP. The Zend Engine compiles PHP source into a format that it can execute, thus the Zend engine works as an interpreter.

php as interpreter language or compiled

Typically, PHP is an interpreted language. The script is read and evaluated at run-time by the interpreter. It is not pre-compiled into a different form.

There are PHP compilers, some which actually compile them, and some which just package/obfuscate the script along with the interpreter into a self-standing executable.

Related question about Zend Engine (actual compiler): How zend engine compile php codes or How php compiler works?

Related product, open source PHP compiler (makes an executable, obfuscates php, includes interpreter): http://www.phpcompiler.org/

php is compiled language or Interpreted language?

PHP is an Interpreted Language : the code you write in your scripts is interpreted -- at least, that's the default.



Wikipedia defines an interpreted language as

a programming language in which
programs are 'indirectly' executed
("interpreted") by an interpreter
program

In the case of PHP, your PHP scripts are interpreted by the PHP executable (which can be embedded in an Apache module -- but the idea remains).



Notes, though, that there are compilers available (but that's not the default setup you'll find in most situations) -- see wikipedia for a list.

PHP Zend engine compile the code or interpreters it

I think the distinction between "compiling" and "interpreting" is less clear in practice than Computer Science lessons would imply, as is the distinction between a "runtime environment" and a "virtual machine".

The answer is essentially that it is both: the Zend Engine first compiles your PHP code to an intermediate representation called "opcodes"; it then interprets these opcodes to execute the code.

In some ways, this is similar to the way Java is first compiled to bytecode, and then executed on the Java Virtual Machine; however, the "VM" which executes the code in the Zend Engine is not defined like a real processor, and is closely tied to the PHP language. It therefore acts more like a traditional interpreter, but of a language that no human would write.

Why compile a PHP File?

While PHP code needs to be interpreted on every call, bytecode is precompiled code that runs almost instantly.
Mostly you will only really need it, if you are running a larger website.

The following tools can be used to compile scripts or run compiled scripts:

  • eAccelerator
  • Zend Optimizer
  • PHC (http://www.phpcompiler.org/)
  • Alternative PHP Cache (APC)

Interpreted vs. Compiled Languages for Web Sites (PHP, ASP, Perl, Python, etc.)

What you can do is what multiple heavy-traffic websites do (like Facebook or Twitter), aka write your "CPU consuming" algorythm in a C-plugin.

For example, you could write a PHP extension if you plan to use PHP, or a Ruby extension if you plan to use Ruby / Ruby on Rails, etc.

That way, you can keep your streamline code simple and easy to maintain (it might be way harder to handle request from C rather than from PHP), while having a strong and solid background core (because it's compiled, and the compiler tells you what the issues are at compile time)

Is the PHP language resultantly C?

That is incorrect.

If you mean the language PHP is implemented in, it is C, not C++; see the PHP wikipedia page, under Implementation Language.

That does not, however, mean that it "translates" code to C; PHP is an interpreted language.

While executing code, it does of course have to use functions written in C, since it is itself using C. However, no "translation" into C occurs; the code is simply parsed by the PHP language and the language then calls, itself, what is appropriate.

You might want to read more on interpreted languages, that should give you a better understanding.



Related Topics



Leave a reply



Submit