com php-src: Added function opcache_is_script_cached( ). (Danack): NEWS ext/opcache/tests/is_script _cached.phpt ext/opcache/zend_accelerator_module.c

From: Date: Fri, 21 Feb 2014 07:59:14 +0000
Subject: com php-src: Added function opcache_is_script_cached( ). (Danack): NEWS ext/opcache/tests/is_script _cached.phpt ext/opcache/zend_accelerator_module.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-76158@lists.php.net to get a copy of this message
Commit: 884bbcd537aad1fcd0265515f69570a20abaf953 Author: Dmitry Stogov <dmitry@zend.com> Fri, 21 Feb 2014 11:59:14 +0400 Parents: e244e2245b9705329d92b92fb0d0d0f50d5af9a4 Branches: PHP-5.5 PHP-5.6 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=884bbcd537aad1fcd0265515f69570a20abaf953 Log: Added function opcache_is_script_cached(). (Danack) Changed paths: M NEWS A ext/opcache/tests/is_script_cached.phpt M ext/opcache/zend_accelerator_module..c Diff: diff --git a/NEWS b/NEWS index 32000e2..d37bb71 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 0000000..6f40a7e --- /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 4de4ab3..b15c080 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)); +}

« previous php.cvs (#76158) next »