Improve PHP 5.5+ program performance with Opcache

Source: Internet
Author: User
Tags apc fpm zend

Description

PHP 5.5 built later OpCache , OpCache the acceleration principle is to store the compiled bytecode in memory, to avoid the duplication of PHP caused by the waste of resources.

Reference
  • How to Enable PHP 5.5 opcache on Ubuntu 14.04
  • Enable PHP 5.5 opcache on Ubuntu 14.04 with Nginx and PHP-FPM
  • How do I use PHP opcache?
How to Enable

Although built, but not enabled by default, the following is an open arrangement, with this set of environment as an example:

PHP 5.5Ubuntu 14.04NginxPHP-FPM
Modify the php.ini file
sudo vim /etc/php5/fpm/php.ini

On the last side of the file, add:

Switch Open opcache.enable=1; available memory, as appropriate, unit megabytesopcache.memory_consumption=   You can try to raise this value by up to opcache.max_accelerated_files=2  , positioning as seconds opcache.revalidate_freq=

Restarting the server

sudo service php5-fpm Restartsudo service nginx Restart

APC VS Opcache

APC is a project that will be abandoned, PHP 5.5 is not supported, and in PHP 5.5 and 5.6, Opcache is built by default and supports 5.2 to 5.4 installations.

How to view effects
    • Projects with a beautiful graphical interface: Https://github.com/PeeHaa/OpCacheGUI
    • Single-file, easy-to-deploy project: Https://github.com/rlerdorf/opcache-status

It is the effect of Phphub when Opcache is turned on (New Relic Monitor background screenshot):

The average response time of PHP is less than 60ms, before it is 130ms

PHP Opcache Configuration
[Opcache]zend_extension="G:/php/php-5.5.6-win32-vc11-x64/ext/php_opcache.dll"; Zend Optimizer+switch, the code is no longer optimized when closed. Opcache.enable=1; DeterminesifZend Opcache isEnabled forThe CLI version of Phpopcache.enable_cli=1; Zend Optimizer+the size of the shared memory, how many precompiled PHP code can be stored in total (MB); recommended -opcache.memory_consumption= -; Zend Optimizer+The total memory of the string in the staging pool. (unit: MB); Recommended8Opcache.interned_strings_buffer=4; The maximum number of cached files $To100000To recommend a relationship between;4000Opcache.max_accelerated_files= -memory "Wasted" reaches the percentage corresponding to this value, and a restart schedule is initiated. Opcache.max_wasted_percentage=5Open this command, Zend Optimizer.+automatically appends the name of the current working directory to the script key, eliminating the key-value naming conflict between files of the same name. Closing this instruction will improve performance, but will cause damage to existing applications. OPCACHE.USE_CWD=0; turn on file timestamp validation opcache.validate_timestamps=1; 2s checking for file updates Note: 0 is always checked not off; recommended -Opcache.revalidate_freq=2allow or disallow the optimization of file search in include_path; Opcache.revalidate_path=0; Do you want to save the file/comment on function if Apigen, Doctrine, ZF2, phpunit need file comment;0opcache.save_comments=1; whether to load files/a comment on a function; opcache.load_comments.=1open Fast close to open this will increase the speed of memory in PHP Request shutdown; recommended1Opcache.fast_shutdown=1allow the optimization of file presence (file_exists, etc.) to be overwritten. ; Opcache.enable_file_override=0; Define how many optimization processes to start; Opcache.optimization_level=0xFFFFFFFFenable this hack to temporarily resolve the "can ' t redeclareclass"error.; o Pcache.inherited_hack=1enable this hack to temporarily resolve the "can ' t redeclareclass"error.; o Pcache.dups_fix=0; Sets a blacklist that does not cache, and does not cache PHP files at the beginning of cache_ in the specified directory./png/www/example.com/public_html/cache/cache_; Opcache.blacklist_filename=; The cache of large files is removed by the file size screen. By default, all files are cached.; o Pcache.max_file_size=0The cache checksum is checked every N times. The default value of 0 indicates that the check is disabled. Due to the calculation of the checksum damage performance, this directive should be tightly opened at the time of development and debugging. O Pcache.consistency_checks=0After the cache is not accessed, the wait time (in seconds) to schedule the restart; Opcache.force_restart_timeout= theerror log file name. Leave blank to indicate the use of standard error output (stderr).; o Pcache.error_log=; Write the error message to the server (Apache etc) log; Opcache.log_verbosity_level=1the preferred background for memory sharing. Leave blank to let the system choose.; o Pcache.preferred_memory_model=prevent accidental writes during script execution within a share, for internal debugging only.; o Pcache.protect_memory=0

Reference:

Http://www.xuebuyuan.com/2039268.html

https://phphub.org/topics/301

Improve PHP 5.5+ program performance with Opcache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.