Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: [ErrorException] Undefined array key "opcache.enable" #8803

Closed
datamweb opened this issue Apr 18, 2024 · 1 comment · Fixed by #8804
Closed

Bug: [ErrorException] Undefined array key "opcache.enable" #8803

datamweb opened this issue Apr 18, 2024 · 1 comment · Fixed by #8804
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@datamweb
Copy link
Contributor

PHP Version

8.3

CodeIgniter4 Version

4.5.1

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

--

What happened?

P:\C4.5.1>php spark phpini:check

CodeIgniter v4.5.1 Command Line Tool - Server Time: 2024-04-18 17:06:41 UTC+00:00

[ErrorException]
Undefined array key "opcache.enable"
at SYSTEMPATH\Security\CheckPhpIni.php:155

Backtrace:
  1    SYSTEMPATH\Security\CheckPhpIni.php:155
       CodeIgniter\Debug\Exceptions()->errorHandler(2, 'Undefined array key "opcache.enable"', 'P:\\laragon\\www\\C4.5.1\\system\\Security\\CheckPhpIni.php', 155)

  2    SYSTEMPATH\Security\CheckPhpIni.php:34
       CodeIgniter\Security\CheckPhpIni::checkIni()

  3    SYSTEMPATH\Commands\Utilities\PhpIniCheck.php:73
       CodeIgniter\Security\CheckPhpIni::run()

  4    SYSTEMPATH\CLI\Commands.php:70
       CodeIgniter\Commands\Utilities\PhpIniCheck()->run([])

  5    SYSTEMPATH\CLI\Console.php:48
       CodeIgniter\CLI\Commands()->run('phpini:check', [])

  6    SYSTEMPATH\Boot.php:338
       CodeIgniter\CLI\Console()->run()

  7    SYSTEMPATH\Boot.php:104
       CodeIgniter\Boot::runCommand(Object(CodeIgniter\CLI\Console))

  8    ROOTPATH\spark:84
       CodeIgniter\Boot::bootSpark(Object(Config\Paths))

Steps to Reproduce

opcache is not required for codeigniter. It is disabled by default in php.ini (;zend_extension=opcache).
This means that there are no ini_get_all() by opcache configuration options.

Expected Output

If ;zend_extension=opcache is set in file php.ini, the output of the command is as follows:

P:\C4.5.1> php spark phpini:check

CodeIgniter v4.5.1 Command Line Tool - Server Time: 2024-04-18 17:15:45 UTC+00:00

+------------------------+-------------------------------+-------------------------------+-------------+-----------------------+
| Directive              | Global                        | Current                       | Recommended | Remark                |
+------------------------+-------------------------------+-------------------------------+-------------+-----------------------+
| error_reporting        | 32767                         | 32767                         | 5111        |                       |
| display_errors         | 1                             | 1                             | 0           |                       |
| display_startup_errors | 1                             | 1                             | 0           |                       |
| log_errors             | 1                             | 1                             |             |                       |
| error_log              | P:/laragon/tmp/php_errors.log | P:/laragon/tmp/php_errors.log |             |                       |
| default_charset        | UTF-8                         | UTF-8                         | UTF-8       |                       |
| memory_limit           | 512M                          | 512M                          |             | > post_max_size       |
| post_max_size          | 2G                            | 2G                            |             | > upload_max_filesize |
| upload_max_filesize    | 2G                            | 2G                            |             | < post_max_size       |
| request_order          | GP                            | GP                            | GP          |                       |
| variables_order        | GPCS                          | GPCS                          | GPCS        |                       |
| date.timezone          | UTC                           | UTC                           | UTC         |                       |
| mbstring.language      | neutral                       | neutral                       | neutral     |                       |
+------------------------+-------------------------------+-------------------------------+-------------+-----------------------+

Anything else?

solution:

   /**
     * @internal Used for testing purposes only.
     * @testTag
     */
    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'],
            'memory_limit'            => ['remark' => '> post_max_size'],
            'post_max_size'           => ['remark' => '> upload_max_filesize'],
            'upload_max_filesize'     => ['remark' => '< post_max_size'],
            'request_order'           => ['recommended' => 'GP'],
            'variables_order'         => ['recommended' => 'GPCS'],
            'date.timezone'           => ['recommended' => 'UTC'],
            'mbstring.language'       => ['recommended' => 'neutral']

        ];

        $ini    = ini_get_all();

        if (array_key_exists('opcache.enable', $ini)) {
            $itemsOpcache = [
                'opcache.enable'          => ['recommended' => '1'],
                'opcache.enable_cli'      => [],
                'opcache.jit'             => [],
                'opcache.jit_buffer_size' => [],
            ];
            
            $items = array_merge($items, $itemsOpcache);
        }

        $output = [];
        
        foreach ($items as $key => $values) {
            $output[$key] = [
                'global'      => $ini[$key]['global_value'],
                'current'     => $ini[$key]['local_value'],
                'recommended' => $values['recommended'] ?? '',
                'remark'      => $values['remark'] ?? '',
            ];
        }

        // [directive => [current_value, recommended_value]]
        return $output;
    }
@datamweb datamweb added the bug Verified issues on the current code behavior or pull requests that will fix them label Apr 18, 2024
@kenjis
Copy link
Member

kenjis commented Apr 18, 2024

Try #8804

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants