Salvador Dali
Salvador Dali

Reputation: 222471

opcache_is_script_cached function in php5.5.11

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.

Upvotes: 1

Views: 777

Answers (3)

Rican7
Rican7

Reputation: 1143

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.

Upvotes: 2

Gino Pane
Gino Pane

Reputation: 5001

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.

Upvotes: 0

grossvogel
grossvogel

Reputation: 6782

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.

Upvotes: 2

Related Questions