Install Zend Opcache in Debian to accelerate PHP

Source: Internet
Author: User
Tags apc pear phpinfo zend

Now more and more based on PHP Web site, there are many mature CMS program to facilitate the use. After the site's traffic increases, the server's requirements for CPU and memory are getting higher. It is not advisable to increase the cost of hardware blindly, and adopting a reasonable caching strategy is an effective way to reduce the server's access pressure. TENNFY will introduce some caching methods for PHP and the database in succession. Today mainly to introduce the use of Zend Opcache accelerated PHP.

Introduction to PHP Caching principle

PHP is a scripting language that, after the interpreter finishes parsing the script code, generates intermediate code that can be run directly, also known as the opcode (Operate code,opcode). The purpose of Opcode cache is to avoid duplication of compilation and reduce CPU and memory overhead. If the performance bottlenecks of dynamic content are not CPU and memory, but I/O operations, such as the disk I/O overhead of database queries, the performance improvement of opcode cache is very limited. But since opcode cache can lead to lower CPU and memory costs, this is a good thing.

Modern opcode buffers (APC, Eaccelerator, XCache, and Zend Opcache) are stored using shared memory and can be executed directly from the file without "deserializing" the code before execution. This will result in significant performance acceleration, which typically lowers memory consumption for the overall server and has few drawbacks. One of the Zend Opcache Plug-ins as the Zend Company's official release of the cache Plug-ins, better caching, can guarantee the latest version of PHP compatible with and update. Therefore, TENNFY recommends installing Zend Opcache for PHP cache acceleration.

Zend Opcache has been integrated into PHP 5.5, but it also supports a lower version of PHP 5.2.*, 5.3.*, 5.4.*, and the following is an introduction to the Zend Opcache installation method.

Zend Opcache Installation Method

The installation method is as follows:


# Install "Pecl" via Php-pear
Apt-get install-y Php-pear

# Install Build Dependencies
Apt-get install-y build-essential Php5-dev

# Install Zend Opcache
PECL Install zendopcache-7.0.5
Add Opcache.ini File

Vi/etc/php5/mods-available/opcache.ini

Add the following lines to the Opcache.ini


Zend_extension=/usr/lib/php5/20100525+lfs/opcache.so
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
128 of which means allocating 128M of memory to it.

Finally, link the file to the CONF.D directory


Ln-s/etc/php5/mods-available/opcache.ini/etc/php5/conf.d/20-opcache.ini

After the modification is complete, restart Nginx and PHP.

View Zend Opcache Effects

Enter Php-v and get the following information


PHP 5.4.45-1~dotdeb+7.1 (CLI) (BUILT:SEP 5 2015 00:21:03)
Copyright (c) 1997-2014 the PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
With Zend Opcache v7.0.5, Copyright (c) 1999-2015, by Zend Technologies
Print out phpinfo () information, and you can see information about Zend Opcache:

In Phpinfo () information, two messages are now important:

Cache Hits (advanced cache hits)
Cache misses (advanced cache misses)
The cache situation can be observed with the above two messages.

Attention matters

After the installation is complete, it is a good idea to uninstall Php5-dev:

Apt-get Remove--purge build-essential Php5-dev

Do not install APC, Eaccelerator, XCache, and Zend Opcache at the same time.

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.