Both sides previous revisionPrevious revision | Next revisionBoth sides next revision |
rfc:opcache.no_cache [2020/05/20 16:12] – tandre | rfc:opcache.no_cache [2020/05/23 14:04] – Improve documentation of ini settings, add another example use case tandre |
---|
| |
''opcache.allow_cache=0'' is useful when there isn't much available memory and/or there are multiple long-lived php scripts managed by something that is not a php script. | ''opcache.allow_cache=0'' is useful when there isn't much available memory and/or there are multiple long-lived php scripts managed by something that is not a php script. |
| Some example use cases are: |
| |
* ''supervisord'' managing hundreds of long-lived PHP CLI processes | * ''supervisord'' managing hundreds of long-lived PHP CLI processes. |
* Tools that run in the background in IDEs for end users of PHP. (Especially if they are long-lived, large applications that don't use ''pcntl_fork'') | * Tools that run in the background in IDEs for end users of PHP. (Especially if they are long-lived, large applications that don't use ''pcntl_fork'') |
| * Long-lived CLI Web Servers where a single CLI process serves many different requests (e.g. [[https://reactphp.org/http/|ReactPHP's HTTP Server]]) |
| |
Even when barely any files are run, the virtual memory to track the shared memory segment seems to add 2MB extra per **independent** php process in "shared memory" segments, reducing the free RAM available for other processes. \\ (starting a large number of php CLI scripts that ''sleep()'' in a loop, ''free'' (Linux program to report free memory) reports that ''shared'' (shared memory) increases by 2MB per process with the default (''opcache.allow_cache=1''), but barely increases with ''opcache.allow_cache=0''. This will vary on different systems, and will use up more memory if many php files are loaded. | Even when barely any files are run, the virtual memory to track the shared memory segment seems to add 2MB extra per **independent** php process in "shared memory" segments, reducing the free RAM available for other processes. \\ (starting a large number of php CLI scripts that ''sleep()'' in a loop, ''free'' (Linux program to report free memory) reports that ''shared'' (shared memory) increases by 2MB per process with the default (''opcache.allow_cache=1''), but barely increases with ''opcache.allow_cache=0''. This will vary on different systems, and will use up more memory if many php files are loaded. |
''opcache.allow_cache=0'' is **not** intended for running web servers (e.g. ''apache''), where PHP would share a common memory address space (it would almost always be better to cache when optimizations are enabled). | ''opcache.allow_cache=0'' is **not** intended for running web servers (e.g. ''apache''), where PHP would share a common memory address space (it would almost always be better to cache when optimizations are enabled). |
| |
''opcache.allow_cache=0'' is also **not** intended for extremely short-lived CLI processes (Opcode optimization may be more time-consuming than the program being run, making the file_cache or ''opcache.enable_cli=0'' a better choice). | ''opcache.allow_cache=0'' is also **not** intended for extremely short-lived CLI processes (Opcode optimization may be more time-consuming than the program being run, making ''opcache.file_cache'' or ''opcache.enable_cli=0'' a better choice). |
| |
==== Interactions with other opcache features ==== | ==== Interactions with other opcache features ==== |
| |
* ''optimizations_enabled'', which is true if any optimization passes will get run. | * ''optimizations_enabled'', which is true if any optimization passes will get run. |
* ''allow_cache'', which will be true if opcache caching is enabled. | * ''allow_cache'', which will be true if opcache caching (in shared memory or the file cache) is enabled. |
| |
| ''opcache_get_status()'' already had the undocumented field ''opcache_enabled''. Looking at the implementation, it appears to be true when shared memory caching is successfully enabled, whether or not optimizations are enabled. Similarly to the existing behavior for ''file_cache_only'', when ''opcache.allow_cache=0'', the field ''opcache_enabled'' will be false. |
| |
==== php.ini Defaults ==== | ==== php.ini Defaults ==== |
| |
''opcache.allow_cache=1'' (caching is allowed) will be the hardcoded default and the default value in php.ini-development and php.ini-production. | ''opcache.allow_cache=1'' (caching is allowed) will be the hardcoded default and the default value in ''php.ini-development'' and ''php.ini-production''. |
| |
===== Discussion ===== | ===== Discussion ===== |
| |
0.2: Previously, the ini setting override to disable caching was ''opcache.no_cache=1''. This was changed to ''opcache.allow_cache=0'' to avoid double negatives and to be consistent with naming of other ini settings such as ''allow_url_fopen'' and ''allow_url_include''. | 0.2: Previously, the ini setting override to disable caching was ''opcache.no_cache=1''. This was changed to ''opcache.allow_cache=0'' to avoid double negatives and to be consistent with naming of other ini settings such as ''allow_url_fopen'' and ''allow_url_include''. |
0.3: Fix documentation of changes to opcache_get_status() | 0.3: Fix documentation of changes to ''opcache_get_status()'' |
| 0.4: Improve documentation of ini settings, add another example use case. |
| |
===== References ===== | ===== References ===== |