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.
Note:
OPcache is only available on Zend Server on PHP 5.5.
Important:
Using the OPcache should not be confused with caching. The OPcache saves a compiled script to the server's memory, while Caching saves the script’s output to the server’s memory.
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:
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 eventsAn event is a collection of runtime-related information collected by the Monitor component. This information is collected when an event is triggered, according to the conditions defined by the Monitoring Rules. 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 Configurations | 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). |