PHP Opcache Acceleration
This article describes how to use PHP Opcache acceleration. The details are as follows:
Introduction
For PHP versions later than 5.5, you can use opcache of PHP to enable performance acceleration (disabled by default ). For PHP versions earlier than 5.5, APC acceleration is required.
Opcache stores pre-compiled bytecode of parsed PHP scripts in the shared memory to avoid the overhead of loading and parsing PHP scripts each time, the parser can directly read the cached bytecode from the shared memory, which greatly improves the execution efficiency of PHP.
Configuration
In PHP 5.5.0 and later versions, PHP has embedded the Opcache function in the released version in the form of an extended library. By default, Opcache acceleration is not enabled, and developers need to go to php. add or uncomment Opcache configurations in ini. For earlier versions, you can use Opcache as the PECL extension library for installation and configuration.
Php. ini:
[Opcache] # Start the operation code to cache opcache. enable = 1 # opcache is usually used to test and debug opcache for PHP Startup operation code caching that supports CLI. enable_cli = 1 # shared memory size, in MBopcache. memory_consumption = 128 # size of temporary String cache stored, in MB. This configuration is ignored before PHP5.3.0. interned_strings_buffer = 8 # maximum number of cached files. The hit rate is less than 100%. You can try to increase the value of opcache. max_accelerated_files = 4000 # Check the file modification time within a certain period of time. Here, set the check time period. The default value is 2, and the Unit is second opcache. revalidate_freq = 60 # enable the fast stop trigger event. dependent on the memory management module of the Zend engine, the memory of all request variables is released at a time, instead of the memory block opcache. fast_shutdo Wn = 1 # enable the PHP script check function to check the existence and readability of the script. Whether the file is cached or not, the operation code cache is checked to improve the performance. However, if the opcache. validate_timestamps option is disabled, there may be risks of returning outdated data. Opcache. enable_file_override = 1
Opcache considerations
1. Opcache makes it unnecessary to use apc and Xcache acceleration;
Because PHP 5.5.0 and later versions have embedded support for Opcache, PHP is aware of its importance. Compared with third-party PHP optimizers such as Xcache, Opcache is a better choice. In addition, the existence of both will greatly reduce the cache hits of Opcache and increase unnecessary overhead.
2. It is not recommended to enable Opcache during development.
After Opcache is enabled, the content modified by the developer is not immediately displayed and takes effect because it is affected by opcache. revalidate_freq = 60. Therefore, we recommend that you test the performance after development and testing. Of course, Opcache is always enabled in the production environment.
3. It is not recommended to set the Opcache indicator too large.
The configuration size or whether the Opcache indicators are enabled depends on the actual needs of the project, the configurations officially recommended by Opcache, and the actual situation analysis of the project, which can be adjusted according to the visual Cache Information Analysis in the fourth part above.
4. We do not recommend that you use the old version of Opcache for a long time.
We recommend that you pay attention to the updates on the Opcache official website and learn about the bug fixes, feature optimizations, and new features in real time so that you can better apply them to your own projects.
5. It is not recommended to add the open-source project described above to the Web Service root directory in the production environment.
The reason is very simple, because this open-source project does not impose access restrictions and security measures. That is to say, users who can access the Internet directly as long as they know the access address, so it is not safe. Generally, this open-source tool only helps to visually analyze the performance of PHP, which is usually used in the Development and debugging phase. If you want to enable it in the production environment, you must do a good job of security restrictions.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.