New Generation PHP Accelerator plugin Zend Opcache

Source: Internet
Author: User
Tags apc phpinfo zts

Reference: Http://www.laogui.com/Zend-Opcache

As you know, PHP currently has three cache plug-ins: APC, Eaccelerator, XCache, but they may all disappear in the future, because PHP 5.5 has integrated Zend Opcache, features similar to the first three but slightly different, Cache speeds are said to be faster than they are (note: It is said that I have not tested it).

The main principles of these PHP acceleration plug-ins are the same, that is, to buffer the PHP data into memory to avoid duplication of the compilation process, the ability to directly use the buffer compiled code to improve speed, reduce server load, their efficiency is obvious, like Drupal this huge CMS, Each time you open a page to call dozens of PHP files, execute tens of thousands of lines of code, the efficiency can be imagined, after installing an APC and other accelerators, the speed of opening the page significantly faster.

Zend Opcache has been integrated in PHP 5.5, compile and install PHP5.5 when added--enable-opcache on the line. But also support the low version of PHP 5.2.*, 5.3.*, 5.4.*, the future will be canceled support for 5.2, below is my installation under PHP 5.4 method:

Execute the following command in turn
wget http://pecl.php.net/get/zendopcache-7.0.2.tgz
Tar xzf zendopcache-7.0.2.tgz
CD zendopcache-7.0.2
Phpize
If you can not find phpize, I find the PHP path, my/usr/local/php/bin/phpize, the following line will also be in accordance with your php.ini path to modify their own
./configure--with-php-config=/usr/local/php/bin/php-config
Make
Make install


If installing shared extensions is displayed:/usr/local/php/lib/php/extensions/no-debug-zts-20100525/indicates that the installation is complete, Here to modify the PHP configuration file to make it effective

Extension of PHP5.3.27 Php_opcache.dll

Test platform: Windows R2 x64 (IIS7.5 fastcgi,apache2.2.23,apache2.4.3, Nginx 1.2.9)

Contains Non thread safe and thread safe

If you are using a FastCGI, use the Non Thread Safe version

How to use Php_opcache.dll


Add the following lines to the last side of the php.ini

[Opcache]

Zend_extension = "D:\phpecorg\PHP\ext\php_opcache.dll"

Or Linux under: zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20100525/opcache.so

opcache.enable = 1

OPCACHE.ENABLE_CLI = 1

Opcache.memory_consumption = 256

Opcache.interned_strings_buffer = 8

Opcache.max_accelerated_files = 4096

Opcache.max_wasted_percentage = 5

Opcache.validate_timestamps = 1

Opcache.revalidate_freq = 60

Opcache.fast_shutdown = 1

Opcache.optimization_level = 0xFFFFFFFF



128 means to allocate 128M of memory to it, then restart Apache, use Phpinfo to see if it takes effect, show the following information is effective



You can see the running status below the Phpinfo page



If this is not intuitive can install a PHP file view, the address in https://gist.github.com/ck-on/4959032, save the above code as a PHP file in your site directory open to see:



Hit 100%.

Zend Opcache Because recently came out, now is the beta version, I believe in the next few years will become more and more popular, and now really not many people use. The current test is still relatively stable, I have been running under the vbulletin forum for a few days, but did not see and APC, XCache What is the difference, just recently my APC old let Apache crashed (may be the Apache and PHP version too new reason), want to change a try, after all Zend Opcache and APC are all PHP official and trustworthy.


Restart Apache, print phpinfo (), and then find Zend Opcache information. Chip

In the phpinfo () message, it is now important to see two messages:

Cache Hits (advanced cache hit)
Cache misses (advanced cache misses)

In these two messages, you can see how the cache is running, at a glance
What optimizations do caches bring? How much help is it to run your code?

Let's do a test to verify what Opcache is.

< PHP
Echo ' Opcache ';
?>

This is a very simple PHP code, please save the demo.php file and then access, feel free to refresh, the Cache hits value will continue to increase, indicating that it worked,
Then you modify the code to:

< PHP
Echo ' Cache new ';
?>

Refresh demo.php, should be able to see the effect, print out the value is still opcache, that is, the source is cached, it no longer resolves demo.php files, try to constantly refresh, detect how many seconds before updating.
Can be set: opcache.force_restart_timeout=180 time to control the update speed.

This is similar to the static file cache in the Web project, for example, we load a Web page, the browser will automatically help us to the JPG, CSS cache, except that PHP is not cached, each time we need open file, parse code, execute code this process, and opcache can solve this problem, The code is cached and the speed of the access is increased.

New Generation PHP Accelerator plugin Zend 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.