Domanda

I know PHP is mostly an interpreted language. Does the PHP interpreter (php.exe in Windows and php file in Linux) do interpretation every time my script executes or only when I change the source? To put it another way, does the PHP interpreter cache interpreted scripts or not?

È stato utile?

Soluzione

This is in essence what happens every time a request arrives:

  • PHP reads the file
  • PHP compiles the file to a language it can process, the so called opcode
  • PHP runs the opcode

There is some overhead in compiling the file into opcode as many have already pointed out, and PHP by default has no cache, so it will do the "compilation" process every time a request arrives even if the file didn't change.

There are some optional modules that can produce opcode caches to avoid that overhead, of which generally the most recommended is APC, since it will ship by default on PHP 6.

Altri suggerimenti

Yes you have a performance penalty as PHP does interpretation every time. Though, if you have APC(Alternative PHP Cache: http://php.net/apc) installed and configured it will keep whole byte code in memory and will re-build it when some changes occur.

Yes.

Being an interpreted language, you do pay a performance penalty. However there is some research in the direction of compiling and using it.

Take a look at PHP Accelerator.

Most PHP accelerators work by caching the compiled bytecode of PHP scripts to avoid the overhead of parsing and compiling source code on each request (some or even most of which may never be executed). To further improve performance, the cached code is stored in shared memory and directly executed from there, minimizing the amount of slow disk reads and memory copying at runtime.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top