略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: 安装

2024-04-28

安装

安装 OPcache 的过程根据所用的 PHP 版本有所不同。 请参考以下小节中适用的内容。

注意:

如果需要将 » Xdebug 扩展和 OPcache 一起使用,必须在 Xdebug 扩展之前加载 OPcache 扩展。

PHP 5.5.0 及后续版本

OPcache 只能编译为共享扩展。 如果你使用 --disable-all 参数 禁用了默认扩展的构建, 那么必须使用 --enable-opcache 选项来开启 OPcache。

编译之后,就可以使用 zend_extension 指令来将 OPcache 扩展加载到 PHP 中。在非 Windows 平台使用 zend_extension=/full/path/to/opcache.so, Windows 平台使用 zend_extension=C:\path\to\php_opcache.dll

PHP 5.2, 5.3 和 5.4 版本

» PECL 扩展未与 PHP 捆绑。

安装此 PECL 扩展相关的信息可在手册中标题为 PECL 扩展的安装章节中找到。更多信息如新的发行版本、下载、源文件、 维护人员信息及变更日志等,都在此处: » https://pecl.php.net/package/ZendOpcache.

PECL 扩展的 DLL 当前不可用。参见 在 Windows 上构建章节。

推荐的 php.ini 设置

使用下列推荐设置来获得较好的 性能:

opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1

你也可以禁用 opcache.save_comments 并且启用 opcache.enable_file_override。 需要提醒的是,在生产环境中使用上述配置之前,必须经过严格测试。 因为上述配置存在一个已知问题,它会引发一些框架和应用的异常, 尤其是在存在文档使用了备注注解的时候。

这里是 OPcache 可用的配置指令完整列表。

add a noteadd a note

User Contributed Notes 3 notes

up
11
stchr
1 year ago
Please note that opcache.fast_shutdown was removed in PHP 7.2
up
24
NoiseEee
8 years ago
While the "suggested" opcache settings for php.ini might be appropriate for a production server, you're going to want to change several while you're developing, or you're not going to see any changes to your code. Get familiar with what they mean before blindly pasting that into php.ini and assuming things are going to work well.
up
-22
ijf8090 at gmail dot com
1 year ago
find the location of your php.ini file by typing
php -i | grep php.ini

Restart your web server to activate your changes
in my case
sudo /usr/sbin/apachectl restart

官方地址:https://www.php.net/manual/en/opcache.installation.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3