From a43d36d9dc7e98124e88fac740c05180778cab89 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Mon, 8 Jul 2024 13:58:25 +0700 Subject: [PATCH 01/14] feat: additional opcache setting in check PHP.ini --- system/Security/CheckPhpIni.php | 41 +++++++++++++---------- tests/system/Security/CheckPhpIniTest.php | 13 +++++++ 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/system/Security/CheckPhpIni.php b/system/Security/CheckPhpIni.php index 59cd587360d5..c129daaa5b36 100644 --- a/system/Security/CheckPhpIni.php +++ b/system/Security/CheckPhpIni.php @@ -118,26 +118,33 @@ private static function outputForWeb(array $output, array $thead, array $tbody): public static function checkIni(): array { $items = [ - 'error_reporting' => ['recommended' => '5111'], - 'display_errors' => ['recommended' => '0'], - 'display_startup_errors' => ['recommended' => '0'], - 'log_errors' => [], - 'error_log' => [], - 'default_charset' => ['recommended' => 'UTF-8'], + 'error_reporting' => ['recommended' => '5111'], + 'display_errors' => ['recommended' => '0'], + 'display_startup_errors' => ['recommended' => '0'], + 'log_errors' => [], + 'error_log' => [], + 'default_charset' => ['recommended' => 'UTF-8'], 'max_execution_time' => ['remark' => 'The default is 30.'], - 'memory_limit' => ['remark' => '> post_max_size'], - 'post_max_size' => ['remark' => '> upload_max_filesize'], - 'upload_max_filesize' => ['remark' => '< post_max_size'], + 'memory_limit' => ['remark' => '> post_max_size'], + 'post_max_size' => ['remark' => '> upload_max_filesize'], + 'upload_max_filesize' => ['remark' => '< post_max_size'], 'max_input_vars' => ['remark' => 'The default is 1000.'], - 'request_order' => ['recommended' => 'GP'], - 'variables_order' => ['recommended' => 'GPCS'], - 'date.timezone' => ['recommended' => 'UTC'], - 'mbstring.language' => ['recommended' => 'neutral'], - 'opcache.enable' => ['recommended' => '1'], - 'opcache.enable_cli' => [], - 'opcache.jit' => [], - 'opcache.jit_buffer_size' => [], + 'request_order' => ['recommended' => 'GP'], + 'variables_order' => ['recommended' => 'GPCS'], + 'date.timezone' => ['recommended' => 'UTC'], + 'mbstring.language' => ['recommended' => 'neutral'], + 'opcache.enable' => ['recommended' => '1'], + 'opcache.enable_cli' => [], + 'opcache.jit' => [], + 'opcache.jit_buffer_size' => [], 'zend.assertions' => ['recommended' => '-1'], + 'opcache.memory_consumption' => ['recommended' => '728', 'remark' => 'Increasing the configured memory size (MB) will improve performance by caching those files'], + 'opcache.interned_strings_buffer' => ['recommended' => '64'], + 'opcache.max_accelerated_files' => ['recommended' => '56000', 'remark' => 'Increasing the configured accelerated will many cache files into OPCache hash table'], + 'opcache.max_wasted_percentage' => ['recommended' => '15'], + 'opcache.validate_timestamps' => ['recommended' => '0'], + 'opcache.revalidate_freq' => ['recommended' => '0'], + 'opcache.save_comments' => ['recommended' => '1'], ]; $output = []; diff --git a/tests/system/Security/CheckPhpIniTest.php b/tests/system/Security/CheckPhpIniTest.php index 8636337f2893..4a0524891a31 100644 --- a/tests/system/Security/CheckPhpIniTest.php +++ b/tests/system/Security/CheckPhpIniTest.php @@ -37,6 +37,19 @@ public function testCheckIni(): void $this->assertSame($expected, $output['display_errors']); } + public function testCheckIniOpcache(): void + { + $output = CheckPhpIni::checkIni(); + + $expected = [ + 'global' => '', + 'current' => '1', + 'recommended' => '1', + 'remark' => '', + ]; + $this->assertSame($expected, $output['opcache.save_comments']); + } + public function testRunCli(): void { // Set MockInputOutput to CLI. From 58edb7b630fa4c4e8494215f0dc263998167d12d Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Mon, 8 Jul 2024 14:05:40 +0700 Subject: [PATCH 02/14] fix: PHPUnit fails --- tests/system/Security/CheckPhpIniTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Security/CheckPhpIniTest.php b/tests/system/Security/CheckPhpIniTest.php index 4a0524891a31..0ffdc64f23e7 100644 --- a/tests/system/Security/CheckPhpIniTest.php +++ b/tests/system/Security/CheckPhpIniTest.php @@ -42,7 +42,7 @@ public function testCheckIniOpcache(): void $output = CheckPhpIni::checkIni(); $expected = [ - 'global' => '', + 'global' => '1', 'current' => '1', 'recommended' => '1', 'remark' => '', From b6cf4cfec1db7d2a3cdfca99d8cdf9f22ead5fcc Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Mon, 8 Jul 2024 14:06:05 +0700 Subject: [PATCH 03/14] fix: remark memory_consumption --- system/Security/CheckPhpIni.php | 1 + 1 file changed, 1 insertion(+) diff --git a/system/Security/CheckPhpIni.php b/system/Security/CheckPhpIni.php index c129daaa5b36..d88c99c81ee6 100644 --- a/system/Security/CheckPhpIni.php +++ b/system/Security/CheckPhpIni.php @@ -139,6 +139,7 @@ public static function checkIni(): array 'opcache.jit_buffer_size' => [], 'zend.assertions' => ['recommended' => '-1'], 'opcache.memory_consumption' => ['recommended' => '728', 'remark' => 'Increasing the configured memory size (MB) will improve performance by caching those files'], + 'opcache.memory_consumption' => ['recommended' => '728', 'remark' => 'Increasing the configured memory size (MB) will improve performance by caching those files (consideration based on free space of memory)'], 'opcache.interned_strings_buffer' => ['recommended' => '64'], 'opcache.max_accelerated_files' => ['recommended' => '56000', 'remark' => 'Increasing the configured accelerated will many cache files into OPCache hash table'], 'opcache.max_wasted_percentage' => ['recommended' => '15'], From ae71f1c59bd82b8a83f5306622548e864ee31745 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Tue, 9 Jul 2024 09:21:56 +0700 Subject: [PATCH 04/14] fix: adjust remark --- system/Security/CheckPhpIni.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/Security/CheckPhpIni.php b/system/Security/CheckPhpIni.php index d88c99c81ee6..19910825540d 100644 --- a/system/Security/CheckPhpIni.php +++ b/system/Security/CheckPhpIni.php @@ -140,8 +140,9 @@ public static function checkIni(): array 'zend.assertions' => ['recommended' => '-1'], 'opcache.memory_consumption' => ['recommended' => '728', 'remark' => 'Increasing the configured memory size (MB) will improve performance by caching those files'], 'opcache.memory_consumption' => ['recommended' => '728', 'remark' => 'Increasing the configured memory size (MB) will improve performance by caching those files (consideration based on free space of memory)'], + 'opcache.memory_consumption' => ['recommended' => '512', 'remark' => 'Adjust with your free space of memory)'], 'opcache.interned_strings_buffer' => ['recommended' => '64'], - 'opcache.max_accelerated_files' => ['recommended' => '56000', 'remark' => 'Increasing the configured accelerated will many cache files into OPCache hash table'], + 'opcache.max_accelerated_files' => ['recommended' => '40000', 'remark' => 'Find many files in your project (example: find your_project/ -iname *.php|wc -l)'], 'opcache.max_wasted_percentage' => ['recommended' => '15'], 'opcache.validate_timestamps' => ['recommended' => '0'], 'opcache.revalidate_freq' => ['recommended' => '0'], From 729effd9a2eb440da28136b31310e11ac3033d48 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Thu, 22 Aug 2024 15:53:55 +0700 Subject: [PATCH 05/14] fix: add argument for opcache only --- system/Commands/Utilities/PhpIniCheck.php | 14 ++++- system/Security/CheckPhpIni.php | 66 +++++++++++++---------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/system/Commands/Utilities/PhpIniCheck.php b/system/Commands/Utilities/PhpIniCheck.php index f65dcd855fa4..df3d8376a7d3 100644 --- a/system/Commands/Utilities/PhpIniCheck.php +++ b/system/Commands/Utilities/PhpIniCheck.php @@ -14,6 +14,7 @@ namespace CodeIgniter\Commands\Utilities; use CodeIgniter\CLI\BaseCommand; +use CodeIgniter\CLI\CLI; use CodeIgniter\Security\CheckPhpIni; /** @@ -56,6 +57,7 @@ final class PhpIniCheck extends BaseCommand * @var array */ protected $arguments = [ + 'opcache' => 'Check detail opcache values in production environment.', ]; /** @@ -70,7 +72,17 @@ final class PhpIniCheck extends BaseCommand */ public function run(array $params) { - CheckPhpIni::run(); + if (isset($params[0]) && ! in_array($params[0], array_keys($this->arguments), true)) { + CLI::error('You must write correct arguments.'); + CLI::write(' Usage: ' . $this->usage); + CLI::write('Example: config:check opcache'); + + return EXIT_ERROR; + } + + $argument = isset($params[0]) && $params[0] ? $params[0] : null; + + CheckPhpIni::run(argument: $argument); return EXIT_SUCCESS; } diff --git a/system/Security/CheckPhpIni.php b/system/Security/CheckPhpIni.php index 19910825540d..8bd43e062441 100644 --- a/system/Security/CheckPhpIni.php +++ b/system/Security/CheckPhpIni.php @@ -29,9 +29,9 @@ class CheckPhpIni * * @return string|void HTML string or void in CLI */ - public static function run(bool $isCli = true) + public static function run(bool $isCli = true, ?string $argument = null) { - $output = static::checkIni(); + $output = static::checkIni($argument); $thead = ['Directive', 'Global', 'Current', 'Recommended', 'Remark']; $tbody = []; @@ -115,40 +115,48 @@ private static function outputForWeb(array $output, array $thead, array $tbody): * @internal Used for testing purposes only. * @testTag */ - public static function checkIni(): array + public static function checkIni(?string $argument = null): array { + // Default items $items = [ - 'error_reporting' => ['recommended' => '5111'], - 'display_errors' => ['recommended' => '0'], - 'display_startup_errors' => ['recommended' => '0'], - 'log_errors' => [], - 'error_log' => [], - 'default_charset' => ['recommended' => 'UTF-8'], + 'error_reporting' => ['recommended' => '5111'], + 'display_errors' => ['recommended' => '0'], + 'display_startup_errors' => ['recommended' => '0'], + 'log_errors' => [], + 'error_log' => [], + 'default_charset' => ['recommended' => 'UTF-8'], 'max_execution_time' => ['remark' => 'The default is 30.'], - 'memory_limit' => ['remark' => '> post_max_size'], - 'post_max_size' => ['remark' => '> upload_max_filesize'], - 'upload_max_filesize' => ['remark' => '< post_max_size'], + 'memory_limit' => ['remark' => '> post_max_size'], + 'post_max_size' => ['remark' => '> upload_max_filesize'], + 'upload_max_filesize' => ['remark' => '< post_max_size'], 'max_input_vars' => ['remark' => 'The default is 1000.'], - 'request_order' => ['recommended' => 'GP'], - 'variables_order' => ['recommended' => 'GPCS'], - 'date.timezone' => ['recommended' => 'UTC'], - 'mbstring.language' => ['recommended' => 'neutral'], - 'opcache.enable' => ['recommended' => '1'], - 'opcache.enable_cli' => [], - 'opcache.jit' => [], - 'opcache.jit_buffer_size' => [], + 'request_order' => ['recommended' => 'GP'], + 'variables_order' => ['recommended' => 'GPCS'], + 'date.timezone' => ['recommended' => 'UTC'], + 'mbstring.language' => ['recommended' => 'neutral'], + 'opcache.enable' => ['recommended' => '1'], + 'opcache.enable_cli' => ['recommended' => '1'], + 'opcache.jit' => ['recommended' => 'tracing'], + 'opcache.jit_buffer_size' => ['recommended' => '256', 'remark' => 'Adjust with your free space of memory)'], 'zend.assertions' => ['recommended' => '-1'], - 'opcache.memory_consumption' => ['recommended' => '728', 'remark' => 'Increasing the configured memory size (MB) will improve performance by caching those files'], - 'opcache.memory_consumption' => ['recommended' => '728', 'remark' => 'Increasing the configured memory size (MB) will improve performance by caching those files (consideration based on free space of memory)'], - 'opcache.memory_consumption' => ['recommended' => '512', 'remark' => 'Adjust with your free space of memory)'], - 'opcache.interned_strings_buffer' => ['recommended' => '64'], - 'opcache.max_accelerated_files' => ['recommended' => '40000', 'remark' => 'Find many files in your project (example: find your_project/ -iname *.php|wc -l)'], - 'opcache.max_wasted_percentage' => ['recommended' => '15'], - 'opcache.validate_timestamps' => ['recommended' => '0'], - 'opcache.revalidate_freq' => ['recommended' => '0'], - 'opcache.save_comments' => ['recommended' => '1'], ]; + if ($argument === 'opcache') { + $items = [ + 'opcache.enable' => ['recommended' => '1'], + 'opcache.enable_cli' => ['recommended' => '1'], + 'opcache.jit' => ['recommended' => 'tracing'], + 'opcache.jit_buffer_size' => ['recommended' => '256', 'remark' => 'Adjust with your free space of memory)'], + 'opcache.memory_consumption' => ['recommended' => '512', 'remark' => 'Adjust with your free space of memory)'], + 'opcache.interned_strings_buffer' => ['recommended' => '64'], + 'opcache.max_accelerated_files' => ['recommended' => '40000', 'remark' => 'Find many files in your project (example: find your_project/ -iname *.php|wc -l)'], + 'opcache.max_wasted_percentage' => ['recommended' => '15'], + 'opcache.validate_timestamps' => ['recommended' => '0'], + 'opcache.revalidate_freq' => ['recommended' => '0'], + 'opcache.save_comments' => ['recommended' => '0'], + ]; + } + $output = []; $ini = ini_get_all(); From 541886975318bb197ba2ce6c559ccbecf66e595b Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Thu, 22 Aug 2024 15:54:19 +0700 Subject: [PATCH 06/14] tests: add argument for opcache only --- .../Commands/Utilities/PhpIniCheckTest.php | 75 +++++++++++++++++++ tests/system/Security/CheckPhpIniTest.php | 4 +- 2 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 tests/system/Commands/Utilities/PhpIniCheckTest.php diff --git a/tests/system/Commands/Utilities/PhpIniCheckTest.php b/tests/system/Commands/Utilities/PhpIniCheckTest.php new file mode 100644 index 000000000000..dd5180acbb5a --- /dev/null +++ b/tests/system/Commands/Utilities/PhpIniCheckTest.php @@ -0,0 +1,75 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\Commands\Utilities; + +use CodeIgniter\Test\CIUnitTestCase; +use CodeIgniter\Test\StreamFilterTrait; +use Config\App; +use PHPUnit\Framework\Attributes\Group; + +/** + * @internal + */ +#[Group('Others')] +final class PhpIniCheckTest extends CIUnitTestCase +{ + use StreamFilterTrait; + + protected function setUp(): void + { + $this->resetServices(); + parent::setUp(); + } + + protected function tearDown(): void + { + $this->resetServices(); + parent::tearDown(); + } + + protected function getBuffer() + { + return $this->getStreamFilterBuffer(); + } + + public function testCommandCheckNoArg(): void + { + command('phpini:check'); + + $result = $this->getBuffer(); + + $this->assertStringContainsString('Directive', $result); + $this->assertStringContainsString('Global', $result); + $this->assertStringContainsString('Current', $result); + $this->assertStringContainsString('Recommended', $result); + $this->assertStringContainsString('Remark', $result); + } + + public function testCommandCheckOpcache(): void + { + command('phpini:check opcache'); + + $this->assertStringContainsString("opcache.save_comments", $this->getBuffer()); + } + + public function testCommandCheckNoExistsArg(): void + { + command('phpini:check noexists'); + + $this->assertStringContainsString( + 'You must write correct arguments.', + $this->getBuffer() + ); + } +} diff --git a/tests/system/Security/CheckPhpIniTest.php b/tests/system/Security/CheckPhpIniTest.php index 0ffdc64f23e7..ba6781d8dd92 100644 --- a/tests/system/Security/CheckPhpIniTest.php +++ b/tests/system/Security/CheckPhpIniTest.php @@ -39,12 +39,12 @@ public function testCheckIni(): void public function testCheckIniOpcache(): void { - $output = CheckPhpIni::checkIni(); + $output = CheckPhpIni::checkIni('opcache'); $expected = [ 'global' => '1', 'current' => '1', - 'recommended' => '1', + 'recommended' => '0', 'remark' => '', ]; $this->assertSame($expected, $output['opcache.save_comments']); From 218b3b10f0c6cbbb2417f5011c134ac532e6471a Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Thu, 22 Aug 2024 16:02:54 +0700 Subject: [PATCH 07/14] fix: typo --- system/Security/CheckPhpIni.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/Security/CheckPhpIni.php b/system/Security/CheckPhpIni.php index 8bd43e062441..12e8524ed91f 100644 --- a/system/Security/CheckPhpIni.php +++ b/system/Security/CheckPhpIni.php @@ -137,7 +137,7 @@ public static function checkIni(?string $argument = null): array 'opcache.enable' => ['recommended' => '1'], 'opcache.enable_cli' => ['recommended' => '1'], 'opcache.jit' => ['recommended' => 'tracing'], - 'opcache.jit_buffer_size' => ['recommended' => '256', 'remark' => 'Adjust with your free space of memory)'], + 'opcache.jit_buffer_size' => ['recommended' => '256', 'remark' => 'Adjust with your free space of memory'], 'zend.assertions' => ['recommended' => '-1'], ]; @@ -146,8 +146,8 @@ public static function checkIni(?string $argument = null): array 'opcache.enable' => ['recommended' => '1'], 'opcache.enable_cli' => ['recommended' => '1'], 'opcache.jit' => ['recommended' => 'tracing'], - 'opcache.jit_buffer_size' => ['recommended' => '256', 'remark' => 'Adjust with your free space of memory)'], - 'opcache.memory_consumption' => ['recommended' => '512', 'remark' => 'Adjust with your free space of memory)'], + 'opcache.jit_buffer_size' => ['recommended' => '256', 'remark' => 'Adjust with your free space of memory'], + 'opcache.memory_consumption' => ['recommended' => '512', 'remark' => 'Adjust with your free space of memory'], 'opcache.interned_strings_buffer' => ['recommended' => '64'], 'opcache.max_accelerated_files' => ['recommended' => '40000', 'remark' => 'Find many files in your project (example: find your_project/ -iname *.php|wc -l)'], 'opcache.max_wasted_percentage' => ['recommended' => '15'], From 36698fcc4769d2e95260be9840a93346c6f38e3d Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Thu, 22 Aug 2024 16:26:06 +0700 Subject: [PATCH 08/14] fix: errors on GA --- system/Commands/Utilities/PhpIniCheck.php | 2 +- tests/system/Commands/Utilities/PhpIniCheckTest.php | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/system/Commands/Utilities/PhpIniCheck.php b/system/Commands/Utilities/PhpIniCheck.php index df3d8376a7d3..f13d3d7f8fe9 100644 --- a/system/Commands/Utilities/PhpIniCheck.php +++ b/system/Commands/Utilities/PhpIniCheck.php @@ -80,7 +80,7 @@ public function run(array $params) return EXIT_ERROR; } - $argument = isset($params[0]) && $params[0] ? $params[0] : null; + $argument = $params[0] ?? null; CheckPhpIni::run(argument: $argument); diff --git a/tests/system/Commands/Utilities/PhpIniCheckTest.php b/tests/system/Commands/Utilities/PhpIniCheckTest.php index dd5180acbb5a..7a5e204dcd2f 100644 --- a/tests/system/Commands/Utilities/PhpIniCheckTest.php +++ b/tests/system/Commands/Utilities/PhpIniCheckTest.php @@ -15,7 +15,6 @@ use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\StreamFilterTrait; -use Config\App; use PHPUnit\Framework\Attributes\Group; /** @@ -38,7 +37,7 @@ protected function tearDown(): void parent::tearDown(); } - protected function getBuffer() + protected function getBuffer(): string { return $this->getStreamFilterBuffer(); } @@ -60,7 +59,7 @@ public function testCommandCheckOpcache(): void { command('phpini:check opcache'); - $this->assertStringContainsString("opcache.save_comments", $this->getBuffer()); + $this->assertStringContainsString('opcache.save_comments', $this->getBuffer()); } public function testCommandCheckNoExistsArg(): void From 3f5526056b1e6a1d63c418b877ab43a5bfd1e9ed Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Fri, 23 Aug 2024 09:35:53 +0700 Subject: [PATCH 09/14] Update system/Commands/Utilities/PhpIniCheck.php Co-authored-by: kenjis --- system/Commands/Utilities/PhpIniCheck.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/system/Commands/Utilities/PhpIniCheck.php b/system/Commands/Utilities/PhpIniCheck.php index f13d3d7f8fe9..aeaa7d4dd2ed 100644 --- a/system/Commands/Utilities/PhpIniCheck.php +++ b/system/Commands/Utilities/PhpIniCheck.php @@ -73,9 +73,15 @@ final class PhpIniCheck extends BaseCommand public function run(array $params) { if (isset($params[0]) && ! in_array($params[0], array_keys($this->arguments), true)) { - CLI::error('You must write correct arguments.'); - CLI::write(' Usage: ' . $this->usage); - CLI::write('Example: config:check opcache'); + CLI::error('You must specify a correct argument.'); + CLI::write(' Usage: ' . $this->usage); + CLI::write(' Example: config:check opcache'); + CLI::write('Arguments:'); + + $length = max(array_map(strlen(...), array_keys($this->arguments))); + foreach ($this->arguments as $argument => $description) { + CLI::write(CLI::color($this->setPad($argument, $length, 2, 2), 'green') . $description); + } return EXIT_ERROR; } From 7826601220828340b682cece031d2fbb0ef89f77 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean <97607754+ddevsr@users.noreply.github.com> Date: Fri, 23 Aug 2024 09:37:06 +0700 Subject: [PATCH 10/14] Update system/Security/CheckPhpIni.php Co-authored-by: kenjis --- system/Security/CheckPhpIni.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Security/CheckPhpIni.php b/system/Security/CheckPhpIni.php index 12e8524ed91f..983b67fb6f76 100644 --- a/system/Security/CheckPhpIni.php +++ b/system/Security/CheckPhpIni.php @@ -149,7 +149,7 @@ public static function checkIni(?string $argument = null): array 'opcache.jit_buffer_size' => ['recommended' => '256', 'remark' => 'Adjust with your free space of memory'], 'opcache.memory_consumption' => ['recommended' => '512', 'remark' => 'Adjust with your free space of memory'], 'opcache.interned_strings_buffer' => ['recommended' => '64'], - 'opcache.max_accelerated_files' => ['recommended' => '40000', 'remark' => 'Find many files in your project (example: find your_project/ -iname *.php|wc -l)'], + 'opcache.max_accelerated_files' => ['remark' => 'Adjust based on the number of PHP files in your project (e.g.: find your_project/ -iname \'*.php\'|wc -l)'], 'opcache.max_wasted_percentage' => ['recommended' => '15'], 'opcache.validate_timestamps' => ['recommended' => '0'], 'opcache.revalidate_freq' => ['recommended' => '0'], From 721f8adab681457fdcdb7fb084df81945ac9e449 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Fri, 23 Aug 2024 12:03:58 +0700 Subject: [PATCH 11/14] fix: typo --- system/Commands/Utilities/PhpIniCheck.php | 3 ++- tests/system/Commands/Utilities/PhpIniCheckTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/system/Commands/Utilities/PhpIniCheck.php b/system/Commands/Utilities/PhpIniCheck.php index aeaa7d4dd2ed..eb2192434133 100644 --- a/system/Commands/Utilities/PhpIniCheck.php +++ b/system/Commands/Utilities/PhpIniCheck.php @@ -75,10 +75,11 @@ public function run(array $params) if (isset($params[0]) && ! in_array($params[0], array_keys($this->arguments), true)) { CLI::error('You must specify a correct argument.'); CLI::write(' Usage: ' . $this->usage); - CLI::write(' Example: config:check opcache'); + CLI::write(' Example: phpini:check opcache'); CLI::write('Arguments:'); $length = max(array_map(strlen(...), array_keys($this->arguments))); + foreach ($this->arguments as $argument => $description) { CLI::write(CLI::color($this->setPad($argument, $length, 2, 2), 'green') . $description); } diff --git a/tests/system/Commands/Utilities/PhpIniCheckTest.php b/tests/system/Commands/Utilities/PhpIniCheckTest.php index 7a5e204dcd2f..9565fd1cf3e9 100644 --- a/tests/system/Commands/Utilities/PhpIniCheckTest.php +++ b/tests/system/Commands/Utilities/PhpIniCheckTest.php @@ -67,7 +67,7 @@ public function testCommandCheckNoExistsArg(): void command('phpini:check noexists'); $this->assertStringContainsString( - 'You must write correct arguments.', + 'You must specify a correct argument.', $this->getBuffer() ); } From a0606f897a973985f35287fe6db96d7019b131a9 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Fri, 23 Aug 2024 15:05:58 +0700 Subject: [PATCH 12/14] refactor: remark certain provisions --- system/Security/CheckPhpIni.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/system/Security/CheckPhpIni.php b/system/Security/CheckPhpIni.php index 983b67fb6f76..d12d252d7685 100644 --- a/system/Security/CheckPhpIni.php +++ b/system/Security/CheckPhpIni.php @@ -144,16 +144,19 @@ public static function checkIni(?string $argument = null): array if ($argument === 'opcache') { $items = [ 'opcache.enable' => ['recommended' => '1'], - 'opcache.enable_cli' => ['recommended' => '1'], - 'opcache.jit' => ['recommended' => 'tracing'], - 'opcache.jit_buffer_size' => ['recommended' => '256', 'remark' => 'Adjust with your free space of memory'], - 'opcache.memory_consumption' => ['recommended' => '512', 'remark' => 'Adjust with your free space of memory'], - 'opcache.interned_strings_buffer' => ['recommended' => '64'], + 'opcache.enable_cli' => ['recommended' => '0', 'remark' => 'Enable when you using CLI'], + 'opcache.jit' => ['recommended' => 'tracing', 'remark' => 'Disable when you used third-party extensions'], + 'opcache.jit_buffer_size' => ['recommended' => '128', 'remark' => 'Adjust with your free space of memory'], + 'opcache.memory_consumption' => ['recommended' => '128', 'remark' => 'Adjust with your free space of memory'], + 'opcache.interned_strings_buffer' => ['recommended' => '16'], 'opcache.max_accelerated_files' => ['remark' => 'Adjust based on the number of PHP files in your project (e.g.: find your_project/ -iname \'*.php\'|wc -l)'], - 'opcache.max_wasted_percentage' => ['recommended' => '15'], - 'opcache.validate_timestamps' => ['recommended' => '0'], - 'opcache.revalidate_freq' => ['recommended' => '0'], - 'opcache.save_comments' => ['recommended' => '0'], + 'opcache.max_wasted_percentage' => ['recommended' => '10'], + 'opcache.validate_timestamps' => ['recommended' => '0', 'remark' => 'When you disabled, opcache hold your code into shared memory. Restart webserver needed'], + 'opcache.revalidate_freq' => [], + 'opcache.file_cache' => ['remark' => 'Location file caching, It should improve performance when SHM memory is full'], + 'opcache.file_cache_only' => ['remark' => 'Opcode caching in shared memory, Disabled when you using Windows'], + 'opcache.file_cache_fallback' => ['remark' => 'Set enable when you using Windows'], + 'opcache.save_comments' => ['recommended' => '0', 'remark' => 'Enable when you using package require docblock annotation'], ]; } From b8649847ffd411aa7d6296109299dbf9adc32670 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Fri, 23 Aug 2024 15:12:06 +0700 Subject: [PATCH 13/14] tests: fix remark save_comments --- tests/system/Security/CheckPhpIniTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Security/CheckPhpIniTest.php b/tests/system/Security/CheckPhpIniTest.php index ba6781d8dd92..e100079dfa79 100644 --- a/tests/system/Security/CheckPhpIniTest.php +++ b/tests/system/Security/CheckPhpIniTest.php @@ -45,7 +45,7 @@ public function testCheckIniOpcache(): void 'global' => '1', 'current' => '1', 'recommended' => '0', - 'remark' => '', + 'remark' => 'Enable when you using package require docblock annotation', ]; $this->assertSame($expected, $output['opcache.save_comments']); } From 3d5fc016d8fe61afe0cd79d2edfd0baec948486a Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Fri, 23 Aug 2024 15:15:15 +0700 Subject: [PATCH 14/14] fix: typo --- system/Security/CheckPhpIni.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Security/CheckPhpIni.php b/system/Security/CheckPhpIni.php index d12d252d7685..d32fadc271c8 100644 --- a/system/Security/CheckPhpIni.php +++ b/system/Security/CheckPhpIni.php @@ -137,7 +137,7 @@ public static function checkIni(?string $argument = null): array 'opcache.enable' => ['recommended' => '1'], 'opcache.enable_cli' => ['recommended' => '1'], 'opcache.jit' => ['recommended' => 'tracing'], - 'opcache.jit_buffer_size' => ['recommended' => '256', 'remark' => 'Adjust with your free space of memory'], + 'opcache.jit_buffer_size' => ['recommended' => '128', 'remark' => 'Adjust with your free space of memory'], 'zend.assertions' => ['recommended' => '-1'], ];