| 
27 | 27 | #include "zend_closures.h"  | 
28 | 28 | #include "zend_shared_alloc.h"  | 
29 | 29 | #include "zend_accelerator_blacklist.h"  | 
 | 30 | +#include "zend_file_cache.h"  | 
30 | 31 | #include "php_ini.h"  | 
31 | 32 | #include "SAPI.h"  | 
32 | 33 | #include "zend_virtual_cwd.h"  | 
@@ -364,6 +365,23 @@ static int filename_is_in_cache(zend_string *filename)  | 
364 | 365 | 	return 0;  | 
365 | 366 | }  | 
366 | 367 | 
 
  | 
 | 368 | +static int filename_is_in_file_cache(zend_string *filename)  | 
 | 369 | +{  | 
 | 370 | +	zend_string *realpath = zend_resolve_path(filename);  | 
 | 371 | +	if (!realpath) {  | 
 | 372 | +		return 0;  | 
 | 373 | +	}  | 
 | 374 | + | 
 | 375 | +	zend_file_handle handle;  | 
 | 376 | +	zend_stream_init_filename_ex(&handle, filename);  | 
 | 377 | +	handle.opened_path = realpath;  | 
 | 378 | + | 
 | 379 | +	zend_persistent_script *result = zend_file_cache_script_load_ex(&handle, true);  | 
 | 380 | +	zend_destroy_file_handle(&handle);  | 
 | 381 | + | 
 | 382 | +	return result != NULL;  | 
 | 383 | +}  | 
 | 384 | + | 
367 | 385 | static int accel_file_in_cache(INTERNAL_FUNCTION_PARAMETERS)  | 
368 | 386 | {  | 
369 | 387 | 	if (ZEND_NUM_ARGS() == 1) {  | 
@@ -999,3 +1017,27 @@ ZEND_FUNCTION(opcache_is_script_cached)  | 
999 | 1017 | 
 
  | 
1000 | 1018 | 	RETURN_BOOL(filename_is_in_cache(script_name));  | 
1001 | 1019 | }  | 
 | 1020 | + | 
 | 1021 | +/* {{{ Return true if the script is cached in OPCache file cache, false if it is not cached or if OPCache is not running. */  | 
 | 1022 | +ZEND_FUNCTION(opcache_is_script_cached_in_file_cache)  | 
 | 1023 | +{  | 
 | 1024 | +	zend_string *script_name;  | 
 | 1025 | + | 
 | 1026 | +	ZEND_PARSE_PARAMETERS_START(1, 1)  | 
 | 1027 | +		Z_PARAM_STR(script_name)  | 
 | 1028 | +	ZEND_PARSE_PARAMETERS_END();  | 
 | 1029 | + | 
 | 1030 | +	if (!validate_api_restriction()) {  | 
 | 1031 | +		RETURN_FALSE;  | 
 | 1032 | +	}  | 
 | 1033 | + | 
 | 1034 | +	if (!(ZCG(accelerator_enabled) || ZCG(accel_directives).file_cache_only)) {  | 
 | 1035 | +		RETURN_FALSE;  | 
 | 1036 | +	}  | 
 | 1037 | + | 
 | 1038 | +	if (!ZCG(accel_directives).file_cache) {  | 
 | 1039 | +		RETURN_FALSE;  | 
 | 1040 | +	}  | 
 | 1041 | + | 
 | 1042 | +	RETURN_BOOL(filename_is_in_file_cache(script_name));  | 
 | 1043 | +}  | 
0 commit comments