Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions ext/opcache/tests/opcache_enable_noop_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Dynamically setting opcache.enable does not warn when noop
--INI--
opcache.enable=1
opcache.enable_cli=1
--EXTENSIONS--
opcache
--FILE--
<?php

echo "Should not warn:", PHP_EOL;
ini_set('opcache.enable', 1);
echo "Disabling:", PHP_EOL;
ini_set('opcache.enable', 0);
echo "Should warn:", PHP_EOL;
ini_set('opcache.enable', 1);

?>
--EXPECTF--
Should not warn:
Disabling:
Should warn:

Warning: Zend OPcache can't be temporarily enabled (it may be only disabled till the end of request) in %s on line %d
18 changes: 18 additions & 0 deletions ext/opcache/tests/opcache_enable_noop_002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Dynamically setting opcache.enable warns when not a noop
--INI--
opcache.enable=0
opcache.enable_cli=1
--EXTENSIONS--
opcache
--FILE--
<?php

echo "Should warn, since the INI was initialized to 0:", PHP_EOL;
ini_set('opcache.enable', 1);

?>
--EXPECTF--
Should warn, since the INI was initialized to 0:

Warning: Zend OPcache can't be temporarily enabled (it may be only disabled till the end of request) in %s on line %d
17 changes: 15 additions & 2 deletions ext/opcache/zend_accelerator_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,23 @@ static ZEND_INI_MH(OnEnable)
stage == ZEND_INI_STAGE_DEACTIVATE) {
return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
} else {
/* It may be only temporary disabled */
/* It may be only temporarily disabled */
bool *p = (bool *) ZEND_INI_GET_ADDR();
if (zend_ini_parse_bool(new_value)) {
zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " can't be temporary enabled (it may be only disabled till the end of request)");
if (*p) {
/* Do not warn if OPcache is enabled, as the update would be a noop anyways. */
return SUCCESS;
}

if (stage == ZEND_INI_STAGE_ACTIVATE) {
if (strcmp(sapi_module.name, "fpm-fcgi") == 0) {
zend_accel_error(ACCEL_LOG_WARNING, ACCELERATOR_PRODUCT_NAME " can't be temporarily enabled. Are you using php_admin_value[opcache.enable]=1 in an individual pool's configuration?");
} else {
zend_accel_error(ACCEL_LOG_WARNING, ACCELERATOR_PRODUCT_NAME " can't be temporarily enabled (it may be only disabled till the end of request)");
}
} else {
zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " can't be temporarily enabled (it may be only disabled till the end of request)");
}
return FAILURE;
} else {
*p = 0;
Expand Down
49 changes: 49 additions & 0 deletions sapi/fpm/tests/opcache_enable_admin_value.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--TEST--
Setting opcache.enable via php_admin_value fails gracefully
--SKIPIF--
<?php include "skipif.inc"; ?>
--FILE--
<?php

require_once "tester.inc";

$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
[unconfined]
listen = {{ADDR}}
pm = static
pm.max_children = 1
catch_workers_output = yes
php_admin_value[opcache.enable] = On
php_admin_flag[display_errors] = On
php_admin_flag[display_startup_errors] = On
php_admin_flag[log_errors] = On
EOT;

$code = <<<EOT
<?php
var_dump(error_get_last());
EOT;

$tester = new FPM\Tester($cfg, $code);
$tester->start(iniEntries: [
'opcache.enable' => '0',
'opcache.log_verbosity_level' => '2',
]);
$tester->expectLogStartNotices();
$tester->expectLogPattern("/Zend OPcache can't be temporarily enabled. Are you using php_admin_value\\[opcache.enable\\]=1 in an individual pool's configuration?/");
echo $tester
->request()
->getBody();
$tester->terminate();
$tester->close();

?>
--EXPECT--
NULL
--CLEAN--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>
Loading