]> granicus.if.org Git - php/commitdiff
Added function opcache_is_script_cached(). (Danack)
authorDmitry Stogov <dmitry@zend.com>
Fri, 21 Feb 2014 07:59:14 +0000 (11:59 +0400)
committerDmitry Stogov <dmitry@zend.com>
Fri, 21 Feb 2014 07:59:14 +0000 (11:59 +0400)
NEWS
ext/opcache/tests/is_script_cached.phpt [new file with mode: 0644]
ext/opcache/zend_accelerator_module.c

diff --git a/NEWS b/NEWS
index 32000e25894af1b41b1eaca04e4626420dee97f2..d37bb71b270f6ec28ab2249900b5c51231c3a200 100644 (file)
--- 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 (file)
index 0000000..6f40a7e
--- /dev/null
@@ -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)
index 4de4ab378ede6c41464a43ca3a77906ca8e20a9a..b15c080c40cd467c709f73113403e0df7d04235b 100644 (file)
@@ -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));
+}