徐善通的随笔

千里之行, 始于足下



php7.4开启opcache的方法


查看opacche.so

首先查看下opcache.so

[root@VM_0_7_centos ~]# ls /usr/local/php/lib/php/extensions/
no-debug-zts-20190902
[root@VM_0_7_centos ~]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20190902/
opcache.a  opcache.so

记录一下opacche.so文件的位置
如果这里没有opcache.so这个文件, 那可能是编译安装php7.4的时候没有添加 --enable-opcache 这个选项, 需要加上这个参数重新编译一下, 这里就不在多说了

编辑php.ini

vim /usr/local/php/etc/php.ini

找到[opcache]模块, 按自己需要修改即可, 但是一定要记得在模块最后添加zend_extension关联opcache.so

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

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

; 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 1000000 are allowed.
opcache.max_accelerated_files=10000

; The maximum percentage of "wasted" memory until a restart is scheduled.
;opcache.max_wasted_percentage=5

; When this directive is enabled, the OPcache appends the current working
; directory to the script key, thus eliminating possible collisions between
; files with the same name (basename). Disabling the directive improves
; performance, but may break existing applications.
;opcache.use_cwd=1

; When disabled, you must reset the OPcache manually or restart the
; webserver for changes to the filesystem to take effect.
;opcache.validate_timestamps=1

; How often (in seconds) to check file timestamps for changes to the shared
; memory storage allocation. ("1" means validate once per second, but only
; once per request. "0" means always validate)
opcache.revalidate_freq=60

; Enables and sets the second level cache directory.
; It should improve performance when SHM memory is full, at server restart or
; SHM reset. The default "" disables file based caching.
opcache.file_cache=/tmp

; Absolute path used to store shared lockfiles (for *nix only).
;opcache.lockfile_path=/tmp

zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20190902/opcache.so

上面的代码, 最后一行zend_extension一定不能忘, 不然即使开启了opcache也是没有效果的

测试

使用 php -m查看一下

[root@VM_0_7_centos ~]# php -m
[PHP Modules]
...
...
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

可以看到,模块里面多了 Zend OPcache, 同时最下面也多出了Zend OPcache的说明

再看一下phpinfo
也是已经开启了opcache

alt


作者: 徐善通
地址: https://www.xstnet.com/article-153.html
声明: 除非本文有注明出处,否则转载请注明本文地址


我有话说



最新回复


正在加载中....

Copyrights © 2016-2019 醉丶春风 , All rights reserved. 皖ICP备15015582号-1