Skip to content

Commit 729effd

Browse files
committed
fix: add argument for opcache only
1 parent ae71f1c commit 729effd

File tree

2 files changed

+50
-30
lines changed

2 files changed

+50
-30
lines changed

system/Commands/Utilities/PhpIniCheck.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace CodeIgniter\Commands\Utilities;
1515

1616
use CodeIgniter\CLI\BaseCommand;
17+
use CodeIgniter\CLI\CLI;
1718
use CodeIgniter\Security\CheckPhpIni;
1819

1920
/**
@@ -56,6 +57,7 @@ final class PhpIniCheck extends BaseCommand
5657
* @var array<string, string>
5758
*/
5859
protected $arguments = [
60+
'opcache' => 'Check detail opcache values in production environment.',
5961
];
6062

6163
/**
@@ -70,7 +72,17 @@ final class PhpIniCheck extends BaseCommand
7072
*/
7173
public function run(array $params)
7274
{
73-
CheckPhpIni::run();
75+
if (isset($params[0]) && ! in_array($params[0], array_keys($this->arguments), true)) {
76+
CLI::error('You must write correct arguments.');
77+
CLI::write(' Usage: ' . $this->usage);
78+
CLI::write('Example: config:check opcache');
79+
80+
return EXIT_ERROR;
81+
}
82+
83+
$argument = isset($params[0]) && $params[0] ? $params[0] : null;
84+
85+
CheckPhpIni::run(argument: $argument);
7486

7587
return EXIT_SUCCESS;
7688
}

system/Security/CheckPhpIni.php

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class CheckPhpIni
2929
*
3030
* @return string|void HTML string or void in CLI
3131
*/
32-
public static function run(bool $isCli = true)
32+
public static function run(bool $isCli = true, ?string $argument = null)
3333
{
34-
$output = static::checkIni();
34+
$output = static::checkIni($argument);
3535

3636
$thead = ['Directive', 'Global', 'Current', 'Recommended', 'Remark'];
3737
$tbody = [];
@@ -115,40 +115,48 @@ private static function outputForWeb(array $output, array $thead, array $tbody):
115115
* @internal Used for testing purposes only.
116116
* @testTag
117117
*/
118-
public static function checkIni(): array
118+
public static function checkIni(?string $argument = null): array
119119
{
120+
// Default items
120121
$items = [
121-
'error_reporting' => ['recommended' => '5111'],
122-
'display_errors' => ['recommended' => '0'],
123-
'display_startup_errors' => ['recommended' => '0'],
124-
'log_errors' => [],
125-
'error_log' => [],
126-
'default_charset' => ['recommended' => 'UTF-8'],
122+
'error_reporting' => ['recommended' => '5111'],
123+
'display_errors' => ['recommended' => '0'],
124+
'display_startup_errors' => ['recommended' => '0'],
125+
'log_errors' => [],
126+
'error_log' => [],
127+
'default_charset' => ['recommended' => 'UTF-8'],
127128
'max_execution_time' => ['remark' => 'The default is 30.'],
128-
'memory_limit' => ['remark' => '> post_max_size'],
129-
'post_max_size' => ['remark' => '> upload_max_filesize'],
130-
'upload_max_filesize' => ['remark' => '< post_max_size'],
129+
'memory_limit' => ['remark' => '> post_max_size'],
130+
'post_max_size' => ['remark' => '> upload_max_filesize'],
131+
'upload_max_filesize' => ['remark' => '< post_max_size'],
131132
'max_input_vars' => ['remark' => 'The default is 1000.'],
132-
'request_order' => ['recommended' => 'GP'],
133-
'variables_order' => ['recommended' => 'GPCS'],
134-
'date.timezone' => ['recommended' => 'UTC'],
135-
'mbstring.language' => ['recommended' => 'neutral'],
136-
'opcache.enable' => ['recommended' => '1'],
137-
'opcache.enable_cli' => [],
138-
'opcache.jit' => [],
139-
'opcache.jit_buffer_size' => [],
133+
'request_order' => ['recommended' => 'GP'],
134+
'variables_order' => ['recommended' => 'GPCS'],
135+
'date.timezone' => ['recommended' => 'UTC'],
136+
'mbstring.language' => ['recommended' => 'neutral'],
137+
'opcache.enable' => ['recommended' => '1'],
138+
'opcache.enable_cli' => ['recommended' => '1'],
139+
'opcache.jit' => ['recommended' => 'tracing'],
140+
'opcache.jit_buffer_size' => ['recommended' => '256', 'remark' => 'Adjust with your free space of memory)'],
140141
'zend.assertions' => ['recommended' => '-1'],
141-
'opcache.memory_consumption' => ['recommended' => '728', 'remark' => 'Increasing the configured memory size (MB) will improve performance by caching those files'],
142-
'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)'],
143-
'opcache.memory_consumption' => ['recommended' => '512', 'remark' => 'Adjust with your free space of memory)'],
144-
'opcache.interned_strings_buffer' => ['recommended' => '64'],
145-
'opcache.max_accelerated_files' => ['recommended' => '40000', 'remark' => 'Find many files in your project (example: find your_project/ -iname *.php|wc -l)'],
146-
'opcache.max_wasted_percentage' => ['recommended' => '15'],
147-
'opcache.validate_timestamps' => ['recommended' => '0'],
148-
'opcache.revalidate_freq' => ['recommended' => '0'],
149-
'opcache.save_comments' => ['recommended' => '1'],
150142
];
151143

144+
if ($argument === 'opcache') {
145+
$items = [
146+
'opcache.enable' => ['recommended' => '1'],
147+
'opcache.enable_cli' => ['recommended' => '1'],
148+
'opcache.jit' => ['recommended' => 'tracing'],
149+
'opcache.jit_buffer_size' => ['recommended' => '256', 'remark' => 'Adjust with your free space of memory)'],
150+
'opcache.memory_consumption' => ['recommended' => '512', 'remark' => 'Adjust with your free space of memory)'],
151+
'opcache.interned_strings_buffer' => ['recommended' => '64'],
152+
'opcache.max_accelerated_files' => ['recommended' => '40000', 'remark' => 'Find many files in your project (example: find your_project/ -iname *.php|wc -l)'],
153+
'opcache.max_wasted_percentage' => ['recommended' => '15'],
154+
'opcache.validate_timestamps' => ['recommended' => '0'],
155+
'opcache.revalidate_freq' => ['recommended' => '0'],
156+
'opcache.save_comments' => ['recommended' => '0'],
157+
];
158+
}
159+
152160
$output = [];
153161
$ini = ini_get_all();
154162

0 commit comments

Comments
 (0)