Working with OPcache
The OPcache runs out-of-the-box (by default, after installation). OPcache allows you to gain a performance boost by reducing code compilation time. When PHP code is compiled for the first time, it is saved in the server’s memory. Each time the code is called, the pre-compiled version is used instead of waiting for the code to compile, which causes a delay each time the code is used.
The general recommendation is to always keep the OPcache loaded to boost Web application performance.
There are some instances where it is preferable not to store PHP byte-code for certain PHP files. To do so, you can make a list (a blacklist) of file names that you want the OPcache to ignore or increase the OPcache resource allocation.
Files and directives should be blacklisted under the following conditions:
- Directories that contain files that are larger than the allocated memory defined in: opcache.memory_consumption or contain more files than the allocated quantity of files, as defined in opcache.max_accelerated_files.
- Large files that have high memory consumption - If you have exhausted all your allocated memory, select the largest and slowest scripts blacklist them.
- Files that have long execution times (makes the compilation save irrelevant).
- Code that is modified on the fly (e.g., auto-generated template files).
Increasing OPcache Resource Allocation
The following procedure describes how to change OPcache resource allocation. This procedure is used as an alternative to blacklisting files and should be tried first, before adding a file to a blacklist (unless the file meets one of the criteria above). OPcache settings can be changed to increase allocated memory and the maximum quantity of files. This alternative depends on the amount of memory available to allocate to the Accelerator.
Memory allocation can only be increased when the OPcache is set to 'On'.
|
|
|
To increase the OPcache memory allocation:
To increase the quantity of files:
|
If the memory fills up quickly (especially if there are only a few files), increase the memory allocation or blacklist the file. Files which exceed the allocated memory or file quantity are not accelerated. |
If none of the alternatives (described above) are suitable, or if the file meets one of the criteria for blacklisting a file, use the following procedure to create a blacklist file that contains the file names of the files you do not want to be byte-code cached by OPcache.
|
|
|
To create a blacklist file:
|
The files in the blacklist are now ignored by OPcache. |
In situations where certain functions were (or were not) defined, some PHP code produces different opcodes, depending on the circumstances. This causes a discrepancy for the OPcache in the situation where the OPcache caches one version and a sequence of events arises that requires a different function. If the discrepancy is not addressed, the script stops working and raises a "duplicate functions" error.
To maintain proper performance in these and similar situations, activate the opcache.dups_fix parameter. This parameter shuts down the OPcache duplicate function check to prevent these errors from occurring.
This parameter can be defined in Administration | Components | OPcache | Directives by searching for opcache.dups_fix.
This procedure describes how to configure the Zend OPcache component.
|
To configure the component:
|
For information on configuring the component daemon directives, see Configuring Component Daemon Directives (Zend Session Clustering, Zend Deployment, Zend Java Bridge, Zend Job Queue, and Zend Monitor). |