Skip to content

Commit 115cd6f

Browse files
committed
opcache: Do not emit “temporary enabling” message when OPcache is already active
An easy way to accidentally enable OPcache “temporarily” is by using `php_admin_value[opcache.enable]=1` within a FPM pool’s configuration, since the `php_admin_value` settings mostly behave like settings in php.ini, with many OPcache INI settings being a notable exception. As long as OPcache is already enabled within php.ini (or simply by default), emitting a warning for `php_admin_value[opcache.enable]=1` or similar is going to be confusing, since is not actually temporarily enabling anything. A follow-up commit will also try to detect this kind of incorrect configuration and try to provide better advice for cases where OPcache is actually not yet enabled.
1 parent b27d919 commit 115cd6f

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Dynamically setting opcache.enable does not warn when noop
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
--EXTENSIONS--
7+
opcache
8+
--FILE--
9+
<?php
10+
11+
echo "Should not warn:", PHP_EOL;
12+
ini_set('opcache.enable', 1);
13+
echo "Disabling:", PHP_EOL;
14+
ini_set('opcache.enable', 0);
15+
echo "Should warn:", PHP_EOL;
16+
ini_set('opcache.enable', 1);
17+
18+
?>
19+
--EXPECTF--
20+
Should not warn:
21+
Disabling:
22+
Should warn:
23+
24+
Warning: Zend OPcache can't be temporary enabled (it may be only disabled till the end of request) in %s on line %d
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Dynamically setting opcache.enable warns when not a noop
3+
--INI--
4+
opcache.enable=0
5+
opcache.enable_cli=1
6+
--EXTENSIONS--
7+
opcache
8+
--FILE--
9+
<?php
10+
11+
echo "Should warn, since the INI was initialized to 0:", PHP_EOL;
12+
ini_set('opcache.enable', 1);
13+
14+
?>
15+
--EXPECTF--
16+
Should warn, since the INI was initialized to 0:
17+
18+
Warning: Zend OPcache can't be temporary enabled (it may be only disabled till the end of request) in %s on line %d

ext/opcache/zend_accelerator_module.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ static ZEND_INI_MH(OnEnable)
162162
/* It may be only temporary disabled */
163163
bool *p = (bool *) ZEND_INI_GET_ADDR();
164164
if (zend_ini_parse_bool(new_value)) {
165+
if (*p) {
166+
/* Do not warn if OPcache is enabled, as the update would be a noop anyways. */
167+
return SUCCESS;
168+
}
169+
165170
zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " can't be temporary enabled (it may be only disabled till the end of request)");
166171
return FAILURE;
167172
} else {

0 commit comments

Comments
 (0)