文字

安装

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

Note:

如果需要将 » 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 扩展的安装章节中找到。更多信息如新的发行版本、下载、源文件、 维护人员信息及变更日志等,都在此处: » http://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 可用的配置指令完整列表。

用户评论:

[#1] Alex Stanciu [2014-12-10 10:34:40]

In case anyone has segfaults when using Xdebug with OpCache (even after updates, Xdebug after OpCache or other desperate strategies).
1. Disable OpCache from beeing loaded
2. Install/Enable APCu
Should be ok for a development box. On the production box you should use OpCache without Xdebug (as Xdebug slows down PHP ~3x - on our apps at least).

[#2] matthias at himalayasystems dot be [2014-05-28 07:37:15]

I had a problem with installing on php 5.4 through pecl

I used 
pecl install ZendOpache-beta
To force the install of the beta version

When restarting, php could not find opcache.so 
Use the absolute path when assigning zend_extension.
So change zend_extension=opache.so
to
zend_extension=/usr/lib64/php/modules/opcache.so

[#3] NoiseEee [2014-03-06 16:34:42]

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.

[#4] dosercz [2013-10-22 10:26:39]

For me works (on windows) only filename without path (default extensions dir path is used)
zend_extension=php_opcache.dll

上一篇: 下一篇: