Skip to content

Commit fb1f245

Browse files
committed
opcache: Improve error message when OPcache is enabled dynamically
The error message will now advice on the `php_admin_value[opcache.enable]=1` mistake. It will also send the message to OPcache’s logging facility instead of the regular error handling logic during startup so that it will not be made available to `error_get_last()`, since it is related to a specific request and thus not actionable by a script either. #19146 made a related change to `opcache.memory_consumption`.
1 parent 115cd6f commit fb1f245

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

ext/opcache/zend_accelerator_module.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,15 @@ static ZEND_INI_MH(OnEnable)
167167
return SUCCESS;
168168
}
169169

170-
zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " can't be temporary enabled (it may be only disabled till the end of request)");
170+
if (stage == ZEND_INI_STAGE_ACTIVATE) {
171+
if (strcmp(sapi_module.name, "fpm-fcgi") == 0) {
172+
zend_accel_error(ACCEL_LOG_WARNING, ACCELERATOR_PRODUCT_NAME " can't be temporary enabled. Are you using php_admin_value[opcache.enable]=1 in an individual pool's configuration?");
173+
} else {
174+
zend_accel_error(ACCEL_LOG_WARNING, ACCELERATOR_PRODUCT_NAME " can't be temporary enabled (it may be only disabled till the end of request)");
175+
}
176+
} else {
177+
zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " can't be temporary enabled (it may be only disabled till the end of request)");
178+
}
171179
return FAILURE;
172180
} else {
173181
*p = 0;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
Setting opcache.enable via php_admin_value fails gracefully
3+
--SKIPIF--
4+
<?php include "skipif.inc"; ?>
5+
--FILE--
6+
<?php
7+
8+
require_once "tester.inc";
9+
10+
$cfg = <<<EOT
11+
[global]
12+
error_log = {{FILE:LOG}}
13+
[unconfined]
14+
listen = {{ADDR}}
15+
pm = static
16+
pm.max_children = 1
17+
catch_workers_output = yes
18+
php_admin_value[opcache.enable] = On
19+
php_admin_flag[display_errors] = On
20+
php_admin_flag[display_startup_errors] = On
21+
php_admin_flag[log_errors] = On
22+
EOT;
23+
24+
$code = <<<EOT
25+
<?php
26+
var_dump(error_get_last());
27+
EOT;
28+
29+
$tester = new FPM\Tester($cfg, $code);
30+
$tester->start(iniEntries: [
31+
'opcache.enable' => '0',
32+
'opcache.log_verbosity_level' => '2',
33+
]);
34+
$tester->expectLogStartNotices();
35+
$tester->expectLogPattern("/Zend OPcache can't be temporary enabled. Are you using php_admin_value\\[opcache.enable\\]=1 in an individual pool's configuration?/");
36+
echo $tester
37+
->request()
38+
->getBody();
39+
$tester->terminate();
40+
$tester->close();
41+
42+
?>
43+
--EXPECT--
44+
NULL
45+
--CLEAN--
46+
<?php
47+
require_once "tester.inc";
48+
FPM\Tester::clean();
49+
?>

0 commit comments

Comments
 (0)