Zend opcache best practice configuration



I saw it on the Internet by accidentAn articleThis guy talked about it very succinctlyZend OpcacheHe said he spent a lot of time exploring the best settings for thisZend OpcacheI think this article is quite instructive, so I specially translate its setting method as follows


This option is used to set the cache expiration time (in seconds). When this time is reached, opcache will check whether your code has changed. If it has changed, PHP will recompile it, generate a new opcode, and update the cache. A value of "0" means that each request will check whether your PHP code has been updated (which means that many stat system calls will be added, Stat system call is to read the status of the file, here is mainly to obtain the latest modification time, this system call will occur disk I / O, so it will inevitably consume some CPU time, of course, the system call itself will also consume some CPU time). You can set it to 0 in the development environment, and do not need to worry about it in the production environment, because another setting option will be introduced below


When this option is enabled (set to 1), PHP will use the_ When the time set by freq arrives, the timestamp of the file is detected


This option is used to control the maximum number of PHP files that can be cached in memory. This option must be set large enough to be larger than the sum of all PHP files in your project. My code base has about 6000 PHP files, so I set this value to a prime number 7963, 7963 is not the minimum prime number greater than 6000). You can run the command "find. - type F - print | grep PHP | WC - L" to quickly calculate the number of PHP files in your code base


The default value of this option is 64MB. I set it to 192mb because my code is very large. You can get the total amount of memory used by opcache by calling opcachegetstatus(). If the value is very large, you can set this option to a larger one


PHP uses a technique called string interning to improve performance. For example, if you use the string "foobar" 1000 times in your code, PHP will only allocate an immutable memory area to store the string when you first use it, Other 999 uses will point directly to this memory area. This option will take this feature to a higher level


Another useful option without documentation is "allow faster shutdown". Its function is to provide a faster mechanism to call the constructor in the code at the end of a single request, so as to speed up the response speed of PHP and the recovery speed of PHP process resources, In this way, the application can respond to the next request more quickly. Set it to 1 to use this mechanism

Finally, we set opcache in php.ini as follows:

opcache.revalidate_ freq=0

Link to the original text:Zend opcache optimal configuration

This work adoptsCC agreementReprint must indicate the author and the link of this article

There is a bright moon in my hometown

Recommended Today

[database] MySQL exercises and answers (educational administration management system)_ MySQL_ 5.7)

✨ statement The answer to the exercise is not guaranteed to be completely correct, which is for reference only MySQL:5.7 Recommended software: Navicat premium Learning SQL statements requires diligent practice! ✨ Field description of each table course CId Course serial number, primary key PCId Prerequisite course DId Opening department number, foreign key CName Course name […]