문제

Recently I asked a question "is there a way to find if the script was hit by opCache" and was not able to find an answer. Right now looking at changelog of Php5.5.11, I found that the new function

OPCache:

Added function opcache_is_script_cached().

was added. Based on the name it is doing exactly what I want, but the problem is that I can not find any documentation on this function.

Can anyone tell me exactly what this function does? Please refrain from wild guesses.

도움이 되었습니까?

해결책

After reading this post (and some other PHP manual notes), I recognized that the function had still yet to be documented. Anyway, I've taken the small bit of time recently to add this function to the PHP documentation:

http://php.net/manual/en/function.opcache-is-script-cached.php

An excerpt from the manual:

opcache_is_script_cached — Tells whether a script is cached in OPCache

boolean opcache_is_script_cached ( string $file )

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.

Returns TRUE if $file is cached in OPCache, FALSE otherwise.

다른 팁

You will find the source code for that function at the bottom of zend_accellerator_module.c, and it does appear to do what you want. It looks like it takes one argument, which is the script filename you're checking. The code in filename_is_in_cache seems to handle cases where the same file is specified by different strings ('filename.php' vs '/var/www/filename.php'), but you can dig deeper or test on your own to verify.

Also, here's a test case showing an example, though it's very minimal.

Actually, a documented function opcache_get_status does what You want. Just call it by passing true parameter in it and checking a scripts section in the returned array.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top