1The Zend OPcache
2================
3
4The Zend OPcache provides faster PHP execution through opcode caching and
5optimization. It improves PHP performance by storing precompiled script
6bytecode in the shared memory. This eliminates the stages of reading code from
7the disk and compiling it on future access. In addition, it applies a few
8bytecode optimization patterns that make code execution faster.
9
10Compatibility
11-------------
12
13This version of Zend OPcache is compatible with PHP 5.2.*, 5.3.*, 5.4.*
14and PHP-5.5 development branch. PHP 5.2 support may be removed in the future.
15
16Quick Install
17-------------
18
19- Compile
20
21 $PHP_DIR/bin/phpize
22 ./configure \
23 --with-php-config=$PHP_DIR/bin/php-config
24 make
25
26- Install
27
28 make install # this will copy opcache.so into PHP extension directory
29
30- Edit php.ini
31
32 zend_extension=/...full path.../opcache.so
33
34NOTE: In case you are going to use Zend OPcache together with Xdebug or Zend Debugger,
35be sure that the debugger is loaded after OPcache. "php -v" must show the debugger
36after OPcache.
37
38- Restart PHP
39
40Speed Tuning
41-------------
42
43We recommend the following configuration options for best performance
44in a production environment.
45
46opcache.memory_consumption=128
47opcache.interned_strings_buffer=8
48opcache.max_accelerated_files=4000
49opcache.revalidate_freq=60
50opcache.fast_shutdown=1
51opcache.enable_cli=1
52
53You also may add the following, but it may break some applications and
54frameworks. Please, read description of these directives and add them on your
55own risk.
56
57opcache.save_comments=0
58opcache.enable_file_override=1
59
60In some cases you may like to prefer enabling/disabling some features
61to avoid incompatibilities at the cost of some performance degradation.
62
63For development environment we would recommend setting opcache.revalidate_freq
64into 0.
65
66Configuration Directives
67------------------------
68
69opcache.enable (default "1")
70 OPcache On/Off switch. When set to Off, code is not optimized and cached.
71
72opcache.enable_cli (default "0")
73 Enables the OPcache for the CLI version of PHP. It's mostly for testing
74 and debugging.
75
76opcache.memory_consumption (default "64")
77 The OPcache shared memory storage size. The amount of memory for storing
78 precompiled PHP code in Mbytes.
79
80opcache.interned_strings_buffer (default "4")
81 The amount of memory for interned strings in Mbytes.
82
83opcache.max_accelerated_files (default "2000")
84 The maximum number of keys (scripts) in the OPcache hash table.
85 The number is actually the first one in the following set of prime
86 numbers that is bigger than the one supplied: { 223, 463, 983, 1979, 3907,
87 7963, 16229, 32531, 65407, 130987, 262237, 524521, 1048793 }. Only numbers
88 between 200 and 1000000 are allowed.
89
90opcache.max_wasted_percentage (default "5")
91 The maximum percentage of "wasted" memory until a restart is scheduled.
92
93opcache.use_cwd (default "1")
94 When this directive is enabled, the OPcache appends the current working
95 directory to the script key, thus eliminating possible collisions between
96 files with the same name (basename). Disabling the directive improves
97 performance, but may break existing applications.
98
99opcache.validate_timestamps (default "1")
100 When disabled, you must reset the OPcache manually or restart the
101 webserver for changes to the filesystem to take effect.
102 The frequency of the check is controlled by the directive
103 "opcache.revalidate_freq".
104
105opcache.validate_permission (default "0")
106 Leads OPcache to check file readability on each access to cached file.
107 This directive should be enabled in shared hosting environment, when few
108 users (PHP-FPM pools) reuse the common OPcache shared memory.
109
110opcache.validate_root (default "0")
111 This directive prevents file name collisions in different "chroot"
112 environments. It should be enabled for sites that may serve requests in
113 different "chroot" environments.
114
115opcache.revalidate_freq (default "2")
116 How often (in seconds) to check file timestamps for changes to the shared
117 memory storage allocation. ("1" means validate once per second, but only
118 once per request. "0" means always validate)
119
120opcache.file_update_protection (default "2")
121 Prevents caching files that are less than this number of seconds old.
122 It protects from caching of incompletely updated files. In case all file
123 updates on your site are atomic, you may increase performance setting it
124 to "0".
125
126opcache.revalidate_path (default "0")
127 Enables or disables file search in include_path optimization
128 If the file search is disabled and a cached file is found that uses
129 the same include_path, the file is not searched again. Thus, if a file
130 with the same name appears somewhere else in include_path, it
131 won't be found. Enable this directive if this optimization has an effect on
132 your applications. The default for this directive is disabled, which means
133 that optimization is active.
134
135opcache.save_comments (default "1")
136 If disabled, all PHPDoc comments are dropped from the code to reduce the
137 size of the optimized code. Disabling "Doc Comments" may break some
138 existing applications and frameworks (e.g. Doctrine, ZF2, PHPUnit)
139
140opcache.fast_shutdown (default "0")
141 If enabled, a fast shutdown sequence is used for the accelerated code
142 The fast shutdown sequence doesn't free each allocated block, but lets
143 the Zend Engine Memory Manager do the work.
144
145opcache.enable_file_override (default "0")
146 Allow file existence override (file_exists, etc.) performance feature.
147
148opcache.optimization_level (default "0xffffffff")
149 A bitmask, where each bit enables or disables the appropriate OPcache
150 passes
151
152opcache.inherited_hack (default "1")
153 Enable this hack as a workaround for "Cannot redeclare class" errors.
154 The OPcache stores the places where DECLARE_CLASS opcodes use
155 inheritance (These are the only opcodes that can be executed by PHP,
156 but which may not be executed because the parent class is missing due to
157 optimization). When the file is loaded, OPcache tries to bind the
158 inherited classes by using the current environment. The problem with this
159 scenario is that, while the DECLARE_CLASS opcode may not be needed for the
160 current script, if the script requires that the opcode at least be defined,
161 it may not run. The default for this directive is disabled, which means
162 that optimization is active. In php-5.3 and above this hack is not needed
163 anymore and this setting has no effect.
164
165opcache.dups_fix (default "0")
166 Enable this hack as a workaround for "Cannot redeclare class" errors.
167
168opcache.blacklist_filename
169 The location of the OPcache blacklist file (wildcards allowed).
170 Each OPcache blacklist file is a text file that holds the names of files
171 that should not be accelerated. The file format is to add each filename
172 to a new line. The filename may be a full path or just a file prefix
173 (i.e., /var/www/x blacklists all the files and directories in /var/www
174 that start with 'x'). Line starting with a ; are ignored (comments).
175 Files are usually triggered by one of the following three reasons:
176 1) Directories that contain auto generated code, like Smarty or ZFW cache.
177 2) Code that does not work well when accelerated, due to some delayed
178 compile time evaluation.
179 3) Code that triggers an OPcache bug.
180
181opcache.max_file_size (default "0")
182 Allows exclusion of large files from being cached. By default all files
183 are cached.
184
185opcache.consistency_checks (default "0")
186 Check the cache checksum each N requests.
187 The default value of "0" means that the checks are disabled.
188 Because calculating the checksum impairs performance, this directive should
189 be enabled only as part of a debugging process.
190
191opcache.force_restart_timeout (default "180")
192 How long to wait (in seconds) for a scheduled restart to begin if the cache
193 is not being accessed.
194 The OPcache uses this directive to identify a situation where there may
195 be a problem with a process. After this time period has passed, the
196 OPcache assumes that something has happened and starts killing the
197 processes that still hold the locks that are preventing a restart.
198 If the log level is 3 or above, a "killed locker" error is recorded
199 in the Apache logs when this happens.
200
201opcache.error_log
202 OPcache error_log file name. Empty string assumes "stderr".
203
204opcache.log_verbosity_level (default "1")
205 All OPcache errors go to the Web server log.
206 By default, only fatal errors (level 0) or errors (level 1) are logged.
207 You can also enable warnings (level 2), info messages (level 3) or
208 debug messages (level 4).
209
210opcache.preferred_memory_model
211 Preferred Shared Memory back-end. Leave empty and let the system decide.
212
213opcache.protect_memory (default "0")
214 Protect the shared memory from unexpected writing during script execution.
215 Useful for internal debugging only.
216
217opcache.restrict_api (default "")
218 Allows calling OPcache API functions only from PHP scripts which path is
219 started from specified string. The default "" means no restriction.
220
221opcache.mmap_base
222 Mapping base of shared memory segments (for Windows only). All the PHP
223 processes have to map shared memory into the same address space. This
224 directive allows to manually fix the "Unable to reattach to base address"
225 errors.
226
227opcache.lockfile_path (default "/tmp")
228 Absolute path used to store shared lockfiles (for *nix only)
229