summaryrefslogtreecommitdiff
path: root/ext/opcache
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2014-02-21 12:00:33 +0400
committerDmitry Stogov <dmitry@zend.com>2014-02-21 12:00:33 +0400
commitb9a87a5079e742b62b641f8521735325c69b762d (patch)
tree0e35c91dfc7cfb9bdca14364306c5114a910897b /ext/opcache
parentdcf27a1f6f205a22ecff1e537de6b13b0f1187ad (diff)
parent884bbcd537aad1fcd0265515f69570a20abaf953 (diff)
downloadphp-git-b9a87a5079e742b62b641f8521735325c69b762d.tar.gz
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: Added function opcache_is_script_cached(). (Danack) Conflicts: NEWS
Diffstat (limited to 'ext/opcache')
-rw-r--r--ext/opcache/tests/is_script_cached.phpt15
-rw-r--r--ext/opcache/zend_accelerator_module.c28
2 files changed, 43 insertions, 0 deletions
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 83e7d4ca2b..da36e0308d 100644
--- a/ext/opcache/zend_accelerator_module.c
+++ b/ext/opcache/zend_accelerator_module.c
@@ -61,9 +61,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);
@@ -75,6 +80,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)
@@ -763,3 +769,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));
+}