PHP Performance Tuning Using an Accelerator - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript PHP Performance Tuning Using an Accelerator - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Saturday, July 6, 2019

PHP Performance Tuning Using an Accelerator

PHP Performance Tuning


Using an Accelerator


Problem

You want to increase performance of your PHP applications.

Solution

Use the Zend OPcache code-caching PHP accelerator to allow PHP to avoid compiling scripts into opcodes on each request.

Discussion

PHP code accelerators do the bulk of their magic transparently by storing compiled versions of PHP scripts on disk or in shared memory in order to skip the compiling step with each request.

When the PHP engine is told to run a particular program, it reads the source code of the program and compiles it into a compact internal representation. Then, it executes the instructions in that compiled representation. When it’s done executing the script, the engine throws away the compiled representation.

An accelerator, by contrast, keeps the compiled instructions around. The next time the PHP engine gets a request to run the same program, the accelerator steps in and checks whether it’s saved a compiled version of that program. If so, it tells the PHP engine to skip recompilation and just execute the already compiled version. An accelerator can be configured to update its compiled representations based on different criteria, such as whenever the original program changes or only when you explicitly tell it to.

As of PHP 5.5, Zend OPcache is automatically built and installed. If you’re running an earlier version of PHP, install it from GitHub or PECL.

Though PHP 5.5 builds Zend OPcache, you still need to turn it on by editing your php.ini file to add a reference to the full path of the extension: zend_extension=/path/to/php/lib/php/extension/debug-non-zts-20121212/opcache.so.

Although you should see a large improvement immediately, you can further improve performance with additional tuning. As a start, update your production configuration parameters to:

       opcache.memory_consumption=128
       opcache.interned_strings_buffer=8
       opcache.max_accelerated_files=4000
       opcache.revalidate_freq=60
       opcache.fast_shutdown=1
       opcache.enable_cli=1

Ultimately, the “right” settings are a balance of factors that depend on the size of the code, how frequently it changes and is called, the amount of memory on your system, and so on. You will need to experiment and use a stress-testing tool to see what’s ideal for your specific system.

No comments:

Post a Comment

Post Top Ad