PHP Opcache accelerated use of the method of explanation

Source: Internet
Author: User
Tags apc php script
This article mainly introduced the PHP Opcache accelerated use method, the small compilation thought quite good, now shares to everybody, also gives everybody to make a reference. Let's take a look at it with a little knitting.

This article introduces the use of PHP opcache acceleration, as follows, to share to you:

Introduced

PHP 5.5+ version above, you can use PHP's own opcache to turn on performance acceleration (the default is off). For PHP versions below 5.5, APC acceleration is required

Opcache is a way to avoid the overhead of loading and parsing PHP scripts by storing the bytecode that is precompiled by the parsed PHP script in shared memory, and the parser can read the cached bytecode directly from the shared memory, thus greatly improving the efficiency of PHP execution.

Configuration

In PHP 5.5.0 and subsequent versions, PHP has embedded the Opcache functionality in the release version, which is not enabled by default Opcache acceleration, requiring developers to add or annotate Opcache related configurations in php.ini. For previous versions, the Opcache can be installed and configured as a PECL expansion library

Ini:

[opcache]# boot opcode cache opcache.enable=1# for support CLI version php boot opcode cache is typically used to test and debug opcache.enable_cli=1# shared memory size in Mbopcache.memory _consumption=128# stores the temporary string cache size, which is mb,php5.3.0 previously ignored this configuration opcache.interned_strings_buffer=8# the maximum number of cache files, the hit rate is less than 100%, Can try to increase this value opcache.max_accelerated_files=4000# check the file modification time within a certain time, here set the check time period, the default is 2, in seconds opcache.revalidate_freq=60# Turn on fast stop and resume events, relying on the memory management module of the Zend Engine, releasing the memory of all request variables at once, instead of freeing the memory block in turn opcache.fast_shutdown=1# enable the ability to check the existence and readability of PHP scripts, regardless of whether the files have been cached or not. Will check the opcode cache to improve performance. However, if the Opcache.validate_timestamps option is disabled, there may be a risk of returning stale data. Opcache.enable_file_override=1

Opcache precautions

1, the use of Opcache is not necessary to use APC and XCache acceleration;

Because PHP 5.5.0 and subsequent versions have embedded support for Opcache, PHP is aware of its importance, and using Opcache is a better choice than a third-party PHP optimizer like XCache. In addition, if both exist, the cache hits of the Opcache are greatly reduced and unnecessary overhead is added.

2, not recommended in the development process to open Opcache

When Opcache is turned on, developer-modified content is not immediately visible and effective because it is affected by opcache.revalidate_freq=60, so it is recommended to test performance after development and testing to open the test, of course, The production environment has always had to open the Opcache.

3. It is not recommended to set the Opcache indicator too large

Opcache each indicator configuration size or whether open, need to combine the actual needs of the project and opcache the official recommendations of the configuration, the actual situation of the project analysis, can be combined with the above fourth part of the visual cache information analysis and adjustment.

4, not recommended long-term use of the old version of Opcache

It is recommended to pay close attention to Opcache website dynamic, real-time understanding of its bugs repair, function optimization and new features, in order to better apply it in their own projects.

5, not recommended in the production environment, the above-mentioned open source project into the Web service root directory

The reason is simple, because this open source project does not do access restrictions and security processing, that is, anyone who can access the extranet, as long as they know the access address can be directly accessible, so it is not secure. Generally, this open source tool only helps visualize the performance of PHP, which is typically used during the development debugging phase. If you want to start working in a production environment, you have to do the security restrictions.
The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support PHP Chinese network.

Articles you may be interested in:

Method of generating Gravatar avatar address using Laravel

Talk about the usage of public,private,protected,abstract and other keywords in PHP

PHP lets you make a new array instance with the same values in the array

Related Article

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.