无法在 AlmaLinux 和 PHP8 上启用 Zend OpCache

问题描述 投票:0回答:2

我正在使用 AlmaLinux 8.4,并且我正在尝试安装 Zend Opcache 并验证它是否正在运行。

在 Easy Apache 中,安装了

php8
php80-php-opcache
php -1
表示 Zend 未启用,而
php -a
已启用,并且
10-opcache.ini
已加载。 (我看到 CLI 未启用,但我不需要它。)

Apache 和 PHP-FPM 已重启多次。

这个配置正确吗?

如何确定 Zend Opcode 是否实际运行?


[root}# php -i
显示:

Zend OPcache

Opcode Caching => Disabled
Optimization => Disabled
SHM Cache => Enabled
File Cache => Disabled
JIT => On
Startup Failed => Opcode Caching is disabled for CLI

Loaded Configuration File => /opt/cpanel/ea-php80/root/etc/php.ini
Additional .ini files parsed => /opt/cpanel/ea-php80/root/etc/php.d/10-opcache.ini

Core

PHP Version => 8.0.9

zend.assertions => -1 => -1
zend.detect_unicode => On => On
zend.enable_gc => On => On
zend.exception_ignore_args => Off => Off
zend.exception_string_param_max_len => 15 => 15
zend.multibyte => Off => Off
zend.script_encoding => no value => no value
zend.signal_check => Off => Off

文件/opt/cpanel/ea-php80/root/etc/php.d/10-opcache.ini显示

Enable Zend OPcache extension module
zend_extension=opcache.so

; Determines if Zend OPCache is enabled
opcache.enable=1

; Determines if Zend OPCache is enabled for the CLI version of PHP
;opcache.enable_cli=0

; The OPcache shared memory storage size.
opcache.memory_consumption=128

; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=8

; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 100000 are allowed.
opcache.max_accelerated_files=4000

php -a 显示

php > print_r(opcache_get_configuration());
Array
(
    [directives] => Array
        (
            [opcache.enable] => 1
            [opcache.enable_cli] => 
            [opcache.use_cwd] => 1
            [opcache.validate_timestamps] => 1
            [opcache.validate_permission] => 1
            [opcache.validate_root] => 
            [opcache.dups_fix] => 
            [opcache.revalidate_path] => 
            [opcache.log_verbosity_level] => 1
            [opcache.memory_consumption] => 134217728
            [opcache.interned_strings_buffer] => 8
            [opcache.max_accelerated_files] => 4000
            [opcache.max_wasted_percentage] => 0.05
            [opcache.consistency_checks] => 0
            [opcache.force_restart_timeout] => 180
            [opcache.revalidate_freq] => 2
            [opcache.preferred_memory_model] => 
            [opcache.blacklist_filename] => /opt/cpanel/ea-php80/root/etc/php.d/opcache*.blacklist
            [opcache.max_file_size] => 0
            [opcache.error_log] => 
            [opcache.protect_memory] => 
            [opcache.save_comments] => 1
            [opcache.record_warnings] => 
            [opcache.enable_file_override] => 
            [opcache.optimization_level] => 2147401727
            [opcache.lockfile_path] => /tmp
            [opcache.file_cache] => 
            [opcache.file_cache_only] => 
            [opcache.file_cache_consistency_checks] => 1
            [opcache.file_update_protection] => 2
            [opcache.opt_debug_level] => 0
            [opcache.restrict_api] => 
            [opcache.huge_code_pages] => 
            [opcache.preload] => 
            [opcache.preload_user] => 
            [opcache.jit] => tracing
            [opcache.jit_buffer_size] => 0
            [opcache.jit_debug] => 0
            [opcache.jit_bisect_limit] => 0
            [opcache.jit_blacklist_root_trace] => 16
            [opcache.jit_blacklist_side_trace] => 8
            [opcache.jit_hot_func] => 127
            [opcache.jit_hot_loop] => 64
            [opcache.jit_hot_return] => 8
            [opcache.jit_hot_side_exit] => 8
            [opcache.jit_max_exit_counters] => 8192
            [opcache.jit_max_loop_unrolls] => 8
            [opcache.jit_max_polymorphic_calls] => 2
            [opcache.jit_max_recursive_calls] => 2
            [opcache.jit_max_recursive_returns] => 2
            [opcache.jit_max_root_traces] => 1024
            [opcache.jit_max_side_traces] => 128
            [opcache.jit_prof_threshold] => 0
        )

    [version] => Array
        (
            [version] => 8.0.9
            [opcache_product_name] => Zend OPcache
        )

    [blacklist] => Array
        (
        )

)
php apache opcache php-8
2个回答
1
投票

要确定

opcache
是否已启用并工作并确保 JIT 实际工作,请创建一个可通过浏览器访问的 PHP 脚本并查看
opcache_get_status()
的输出。

示例 PHP 文件可以是:

var_dump(opcache_get_status());

启用时的输出示例为:

array(9) {
  ["opcache_enabled"]=>
  bool(true)
...

如果未安装或未启用 opcache 扩展,则会抛出此错误:

Fatal error:  Uncaught Error: Call to undefined function opcache_get_status()

另一种选择是打印 phpinfo 并检查输出中的 opcache:

<?php phpinfo(); ?>


0
投票

这确定是否为 PHP 的 CLI 版本启用 Zend OPCache

opcache.enable_cli=0

可能是这个原因

© www.soinside.com 2019 - 2024. All rights reserved.