Opcache PHP New byte code cache extension detailed

Source: Internet
Author: User
Tags apc memory usage php file php code zend

Byte code cache component Zend optimizer+ now change the name to Zend Opcache. And after the PHP 5.5 version, will be integrated into the official PHP components, there is no need to install other apc,eaccelerator and so on.

APC and Opcache are bytecode caches that is, when PHP is compiled, PHP code is first converted to bytecode, and bytecode is then executed.

PHP file for the second time, the same will be converted to bytecode, but many times, the contents of the file is almost the same, such as static HTML files, generated after a long time will not change, user access requests directly from the server read the response to the client browser. Do not have to go through PHP to parse the build.

In-memory byte code data, which can be directly cached for two compile times. This program will be faster, CPU consumption is also less.

Read more about these two articles

Next-generation PHP accelerator plugin Zend Opcache

PHP's Zend Opcache VS APC Performance comparison

I was mainly used to test the phpcmsV9.5.4 default index.php home page, no data content, but there are SQL query operations

Test is Apache2.2.6 32Bit server, PHP 5.4.26 ts,mysql 5.6.16 64Bit

AB version This is apachebench, version 2.3 < $Revision: 655654 $>

Number of requests: 1000

Concurrent numbers: 10

Opcache Test not loaded

First time Test


Throughput 38.46 RPS, time-consuming 26.001 s, time consuming per request 260.015 ms
Second Test

Throughput increased 40.73 RPS, time-consuming 24.554 s, per request time-consuming 245.544 ms

Load Opcache for testing
Opcache version Php_opcache-7.0.3-5.4-ts-vc9-x86

Opcache configuration information

1 opcache.memory_consumption=128
2 opcache.interned_strings_buffer=8
3 opcache.max_accelerated_files=4000
4 opcache.revalidate_freq=60
5 opcache.fast_shutdown=1
6 opcache.enable_cli=1
First time Configure Opcache cache status
Cache Hits hit number 1
Cache misses misses number 1
Use memory 225.2Kb
Opcache First Test
Throughput up to 49.11rps, total time consuming 20.361 s, and each request takes time to drop to 203.612 ms
To view the number of Opcache hits in Phpinfo
The number of hits has reached 43957 and memory usage is 2.31Mb.
Opcache Second Test
Throughput up to 47.87rps, total time consuming 20.888 s, and each request takes time to drop to 208.882 ms
After the Opcache two times the pressure measured data changes little, each request time is in the 1ms disparity, the throughput rate also is 1~2 RPS
But with the previous not enabled Opcache, the total time is less than 4 ~ 6 S, each request time-consuming less than the MS. The throughput rate also increased by 8%.
This is the case where a single line of code does not change the effectiveness can be improved.
PHP files are compiled into bytecode for memory caching, and if the code and content variables are more fixed in the build environment
The cached content can be returned at a high speed, and the user will get a quicker response.
However, local development is not recommended to open Opcache, otherwise you will not get the latest value

For example:

<?php
 header (' content-type:text/html; Charset=utf-8 ');
 
  $STR = ' A BC ';
 echo $str//output ABC


give $str a new value

<?php
 header (' content-type:text/ html Charset=utf-8 ');
 
  $STR = ' new abc ';
 echo $str//Output or ABC

This is because $STR has been compiled into bytecode, and when accessed again, the memory Face or can find the corresponding cache, there is no recompilation, the return value is also the previous value of ABC

However, Opcache has a parameter that can be used to set the cache time length


Opcache.force_restart_ Timeout (default "180")

defaults to 180 seconds, or it is recommended that you do not need to open opcache

 

Note: The official gave a notes if Opcache to be loaded with Xdebug at the same time , then Opcache needs to be loaded before xdebug.

But I have a local test, xdebug first load, then load Opcache, also normal startup, Xdebug,opcache loaded successfully, Opcache cache is normal.

But install the load according to the official recommendation, or there may be a strange error.

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.