Hacker News new | ask | show | jobs
by worldhello 6263 days ago
"In fact, that's a distinct advantage of mod_php. Everything is loaded and in memory when the request comes in. Throw APC on top of that and your code is also already compiled."

I would love it if someone cleared a very basic doubt of mine : If php is compiled, then what is the advantage of other programming languages? Wouldn't it be the same as anything else (except maybe considering the size of the language)? Is it just the optimization of the compiler then? And if so, would PHP compare the same to other loosely typed languages?

1 comments

If PHP is compiled, then it still has almost the same benefits and drawbacks compared to all the other languages, except for one: once it's compiled, PHP runs faster than it does when interpreted. Simple.

IIRC the compiler for PHP uses a scheme compiler as a backend.

So then APC + PHP == (compiled python) == (compiled ruby) == C ? Sorry am not a python or ruby person so don't know how compiled code works out there.
Let's say you write a Python program that outputs Javascript. It could be considered a "compiler". Or let's say that you write your own language, which outputs to other 3 or 4... there's also compiling involved. A compiler doesn't need to output assembler. Even if every compiler did that, features of the language would result in different execution code.

For example, PHP's variables can be a string of any size, or a number, or an object, and you can change its type while the program is running. The compiler doesn't optimize the code execution as easy as, say, in Java. You can not allocated the minimum amount of memory that will store the variable values, for example.