Does PHP have a built-in optimizer?

How will MySQL Optimizer convert queries to more efficient queries as it sees fit, is there a similar optimization process going on behind the scenes with PHP? Where does PHP take your code, parse it, and convert it to be more efficient before everything is executed?

+7
source share
2 answers

PHP uses a one-pass compilation process in which it converts the source code into an operation code stream (which is then executed). Since compilation uses only one pass and does not create an AST, most of the optimizations usually performed by other languages ​​would be very difficult to implement. Obviously, some simple optimizations are performed (for example, interning strings and pre-characters), but most “advanced” optimizations are simply not possible.

By the way, a very simple way to “optimize” the PHP code is to cache the created stream of the operation code using the APC extension so that it does not recreate every time the page is loaded: the compilation process is quite resource-intensive, and using APC can often slightly decrease the load on your processor.

+4
source

PHP itself probably does some optimizations during the interpretation, although I don’t know any significant ones.

But since PHP is extensible, a number of so-called PHP accelerators can be found on the Internet. Accelerator is a PHP extension that does a certain form of optimization for you, usually using caching of operation code or the like.

Differences between interpretation (which makes the standard PHP distribution) and compilation, several PHP compilers are available. You can pass the PHP code through the PHP compiler, which (and does not interpret and execute the code on the fly) creates an optimized executable format for you.

+1
source

All Articles