如何使用PHP OPCache? [英] How to use PHP OPCache?
问题描述
PHP 5.5已发布,它具有一个称为OPCache的新代码缓存模块,但似乎没有任何文档.
PHP 5.5 has been released and it features a new code caching module called OPCache, but there doesn't appear to be any documentation for it.
那么它的文档在哪里以及如何使用OPcache?
So where is the documentation for it and how do I use OPcache?
推荐答案
安装
OpCache默认在PHP5.5 +上编译.但是,默认情况下它是禁用的.为了开始在PHP5.5 +中使用OpCache,您首先必须启用它.为此,您必须执行以下操作.
Installation
OpCache is compiled by default on PHP5.5+. However it is disabled by default. In order to start using OpCache in PHP5.5+ you will first have to enable it. To do this you would have to do the following.
将以下行添加到您的php.ini
:
zend_extension=/full/path/to/opcache.so (nix)
zend_extension=C:\path\to\php_opcache.dll (win)
请注意,当路径包含空格时,应将其用引号引起来:
Note that when the path contains spaces you should wrap it in quotes:
zend_extension="C:\Program Files\PHP5.5\ext\php_opcache.dll"
还请注意,您必须使用zend_extension
指令而不是"normal" extension
指令,因为它会影响实际的Zend引擎(即运行PHP的东西).
Also note that you will have to use the zend_extension
directive instead of the "normal" extension
directive because it affects the actual Zend engine (i.e. the thing that runs PHP).
当前可以使用四个功能:
Currently there are four functions which you can use:
返回一个数组,其中包含OpCache使用的当前使用的配置.这包括所有ini设置以及版本信息和列入黑名单的文件.
Returns an array containing the currently used configuration OpCache uses. This includes all ini settings as well as version information and blacklisted files.
var_dump(opcache_get_configuration());
opcache_get_status()
:
这将返回一个数组,其中包含有关缓存当前状态的信息.这些信息将包括以下内容:高速缓存的状态(启用,重新启动,已满等),内存使用情况,命中,未命中以及更多有用的信息.它还将包含缓存的脚本.
opcache_get_status()
:
This will return an array with information about the current status of the cache. This information will include things like: the state the cache is in (enabled, restarting, full etc), the memory usage, hits, misses and some more useful information. It will also contain the cached scripts.
var_dump(opcache_get_status());
opcache_reset()
:
重置整个缓存.意味着下次访问时将再次解析所有可能的缓存脚本.
opcache_reset()
:
Resets the entire cache. Meaning all possible cached scripts will be parsed again on the next visit.
opcache_reset();
opcache_invalidate()
:
使特定的缓存脚本无效.这意味着该脚本将在下次访问时再次解析.
opcache_invalidate()
:
Invalidates a specific cached script. Meaning the script will be parsed again on the next visit.
opcache_invalidate('/path/to/script/to/invalidate.php', true);
维护和报告
创建了一些GUI,以帮助维护OpCache并生成有用的报告.这些工具利用了上述功能.
Maintenance and reports
There are some GUI's created to help maintain OpCache and generate useful reports. These tools leverage the above functions.
OpCacheGUI
OpCacheGUI
免责声明我是该项目的作者
功能:
- OpCache状态
- OpCache配置
- OpCache统计信息
- OpCache重置
- 缓存脚本概述
- 缓存脚本无效
- 多语言
- 移动设备支持
- 发光图
屏幕截图:
URL: https://github.com/PeeHaa/OpCacheGUI
opcache状态
opcache-status
功能:
- OpCache状态
- OpCache配置
- OpCache统计信息
- 缓存脚本概述
- 单个文件
屏幕截图:
URL: https://github.com/rlerdorf/opcache-status
opcache-gui
opcache-gui
功能:
- OpCache状态
- OpCache配置
- OpCache统计信息
- OpCache重置
- 缓存脚本概述
- 缓存脚本无效
- 自动刷新
屏幕截图:
URL: https://github.com/amnuts/opcache-gui
这篇关于如何使用PHP OPCache?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!