Ref/opcache-Phpdoc专题
opcache_compile_file
无需运行,即可编译并缓存 PHP 脚本
说明
boolean <span
class="methodname">opcache_compile_file ( <span
class="methodparam">string $file
)
该函数可以用于在不用运行某个 PHP 脚本的情况下,编译该 PHP 脚本并将其添加到字节码缓存中去。 该函数可用于在 Web 服务器重启之后初始化缓存,以供后续请求调用。
参数
file
被编译的 PHP 脚本的路径。
返回值
如果 file
被成功编译,则返回 true
或者在失败时返回 false
。
错误/异常
如果文件( file
)不能被载入或者不能被编译,则会生成一个
E_WARNING
级别的错误。 可以使用
@
来抑制该警告。
参见
- opcache_invalidate
opcache_get_configuration
获取缓存的配置信息
说明
array <span class="methodname">opcache_get_configuration ( <span class="methodparam">void )
该函数将返回缓存实例的配置信息。
返回值
返回一个数组,该数组里包含了缓存的初始化信息,黑名单和版本号。
错误/异常
在启用了 opcache.restrict_api 的情况下,如果当前路径在禁止规则里,将会出现 E_WARNING ;不会返回任何状态信息。
参见
- opcache_get_status
opcache_get_status
获取缓存的状态信息
说明
array <span
class="methodname">opcache_get_status ([ <span
class="methodparam">boolean
$get_scripts
= true
] )
该函数将返回缓存实例的状态信息。
参数
get_scripts
包含脚本的具体声明信息。
返回值
返回一个数组,该数组可能包含有脚本具体的声明信息。
错误/异常
在启用了 opcache.restrict_api 的情况下,如果当前路径在禁止规则里,将会出现 E_WARNING ;不会返回任何状态信息。
参见
- opcache_get_configuration
opcache_invalidate
废除脚本缓存
说明
boolean <span
class="methodname">opcache_invalidate ( <span
class="methodparam">string $script
[, boolean
$force
= false
] )
该函数的作用是使得指定脚本的字节码缓存失效。 如果 force
没有设置或者传入的是 false
,那么只有当脚本的修改时间
比对应字节码的时间更新,脚本的缓存才会失效。
参数
script
缓存需要被作废对应的脚本路径
force
如果该参数设置为true
,那么不管是否必要,该脚本的缓存都将被废除。
返回值
如果脚本的字节码缓存失效设置成功或者该脚本本来就没有缓存,则返回
true
;如果字节码缓存被禁用,则返回false
。
参见
- opcache_compile_file
- opcache_reset
opcache_is_script_cached
Tells whether a script is cached in OPCache
说明
bool <span
class="methodname">opcache_is_script_cached ( <span
class="methodparam">string $filename
)
This function checks if a PHP script has been cached in OPCache. This can be used to more easily detect the "warming" of the cache for a particular script.
参数
filename
The path to the PHP script to be checked.
返回值
Returns true
if filename
is cached in OPCache, false
otherwise.
参见
- opcache_compile_file
opcache_reset
重置字节码缓存的内容
说明
boolean <span class="methodname">opcache_reset ( <span class="methodparam">void )
该函数将重置整个字节码缓存。 在调用 <span class="function">opcache_reset 之后,所有的脚本将会重新载入并且在下次被点击的时候重新解析。
参数
此函数没有参数。
返回值
如果字节码缓存被重置成功,则返回
true
;如果字节码缓存被禁用,则返回 false
。
参见
- opcache_invalidate
目录
- opcache_compile_file — 无需运行,即可编译并缓存 PHP 脚本
- opcache_get_configuration — 获取缓存的配置信息
- opcache_get_status — 获取缓存的状态信息
- opcache_invalidate — 废除脚本缓存
- opcache_is_script_cached — Tells whether a script is cached in OPCache
- opcache_reset — 重置字节码缓存的内容