summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--ext/opcache/tests/is_script_cached.phpt15
-rw-r--r--ext/opcache/zend_accelerator_module.c28
3 files changed, 46 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 32000e2589..d37bb71b27 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,9 @@ PHP NEWS
. Implemented ldap_modify_batch (https://wiki.php.net/rfc/ldap_modify_batch).
(Ondřej Hošek)
+- OPCache
+ . Added function opcache_is_script_cached(). (Danack)
+
- Openssl:
. Fixed bug #66501 (Add EC key support to php_openssl_is_private_key).
(Mark Zedwood)
diff --git a/ext/opcache/tests/is_script_cached.phpt b/ext/opcache/tests/is_script_cached.phpt
new file mode 100644
index 0000000000..6f40a7e35d
--- /dev/null
+++ b/ext/opcache/tests/is_script_cached.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Test that script cached info is correct
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+var_dump(opcache_is_script_cached(__FILE__));
+var_dump(opcache_is_script_cached("nonexistent.php"));
+?>
+--EXPECT--
+bool(true)
+bool(false)
diff --git a/ext/opcache/zend_accelerator_module.c b/ext/opcache/zend_accelerator_module.c
index 4de4ab378e..b15c080c40 100644
--- a/ext/opcache/zend_accelerator_module.c
+++ b/ext/opcache/zend_accelerator_module.c
@@ -57,9 +57,14 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_opcache_invalidate, 0, 0, 1)
ZEND_ARG_INFO(0, force)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_opcache_is_script_cached, 0, 0, 1)
+ ZEND_ARG_INFO(0, script)
+ZEND_END_ARG_INFO()
+
/* User functions */
static ZEND_FUNCTION(opcache_reset);
static ZEND_FUNCTION(opcache_invalidate);
+static ZEND_FUNCTION(opcache_is_script_cached);
/* Private functions */
static ZEND_FUNCTION(opcache_get_status);
@@ -71,6 +76,7 @@ static zend_function_entry accel_functions[] = {
ZEND_FE(opcache_reset, arginfo_opcache_none)
ZEND_FE(opcache_invalidate, arginfo_opcache_invalidate)
ZEND_FE(opcache_compile_file, arginfo_opcache_compile_file)
+ ZEND_FE(opcache_is_script_cached, arginfo_opcache_is_script_cached)
/* Private functions */
ZEND_FE(opcache_get_configuration, arginfo_opcache_none)
ZEND_FE(opcache_get_status, arginfo_opcache_get_status)
@@ -759,3 +765,25 @@ static ZEND_FUNCTION(opcache_compile_file)
}
zend_destroy_file_handle(&handle TSRMLS_CC);
}
+
+/* {{{ proto bool opcache_is_script_cached(string $script)
+ Return true if the script is cached in OPCache, false if it is not cached or if OPCache is not running. */
+static ZEND_FUNCTION(opcache_is_script_cached)
+{
+ char *script_name;
+ int script_name_len;
+
+ if (!validate_api_restriction(TSRMLS_C)) {
+ RETURN_FALSE;
+ }
+
+ if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled)) {
+ RETURN_FALSE;
+ }
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &script_name, &script_name_len) == FAILURE) {
+ return;
+ }
+
+ RETURN_BOOL(filename_is_in_cache(script_name, script_name_len TSRMLS_CC));
+}