#include "zend_virtual_cwd.h"
#include "zend_accelerator_util_funcs.h"
#include "zend_accelerator_hash.h"
+#include "zend_file_cache.h"
#include "ext/pcre/php_pcre.h"
#include "ext/standard/md5.h"
-#ifdef HAVE_OPCACHE_FILE_CACHE
-# include "zend_file_cache.h"
-#endif
-
#ifndef ZEND_WIN32
#include <netdb.h>
#endif
zend_bool accel_startup_ok = 0;
static char *zps_failure_reason = NULL;
char *zps_api_failure_reason = NULL;
-#ifdef HAVE_OPCACHE_FILE_CACHE
zend_bool file_cache_only = 0; /* process uses file cache only */
-#endif
#if ENABLE_FILE_CACHE_FALLBACK
zend_bool fallback_process = 0; /* process uses file cache fallback */
#endif
uint32_t pos, *hash_slot;
zend_string *s;
-#ifdef HAVE_OPCACHE_FILE_CACHE
if (UNEXPECTED(file_cache_only)) {
return str;
}
-#endif
if (IS_ACCEL_INTERNED(str)) {
/* this is already an interned string */
return FAILURE;
}
-#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache) {
zend_file_cache_invalidate(realpath);
}
-#endif
persistent_script = zend_accel_hash_find(&ZCSG(hash), realpath);
if (persistent_script && !persistent_script->corrupted) {
!strstr(ZSTR_VAL(filename), "://");
}
-#ifdef HAVE_OPCACHE_FILE_CACHE
static zend_persistent_script *store_script_in_file_cache(zend_persistent_script *new_persistent_script)
{
uint32_t memory_used;
*from_shared_memory = 1;
return store_script_in_file_cache(new_persistent_script);
}
-#endif
static zend_persistent_script *cache_script_in_shared_memory(zend_persistent_script *new_persistent_script, const char *key, unsigned int key_length, int *from_shared_memory)
{
}
orig_compiler_options = CG(compiler_options);
-#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache) {
CG(compiler_options) |= ZEND_COMPILE_WITH_FILE_CACHE;
}
-#endif
if (!zend_optimize_script(&new_persistent_script->script, ZCG(accel_directives).optimization_level, ZCG(accel_directives).opt_debug_level)) {
CG(compiler_options) = orig_compiler_options;
return new_persistent_script;
ZSMMG(memory_exhausted) = 1;
zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_HASH);
zend_shared_alloc_unlock();
-#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache) {
new_persistent_script = store_script_in_file_cache(new_persistent_script);
*from_shared_memory = 1;
}
-#endif
return new_persistent_script;
}
zend_shared_alloc_destroy_xlat_table();
zend_accel_schedule_restart_if_necessary(ACCEL_RESTART_OOM);
zend_shared_alloc_unlock();
-#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache) {
new_persistent_script = store_script_in_file_cache(new_persistent_script);
*from_shared_memory = 1;
}
-#endif
return new_persistent_script;
}
zend_shared_alloc_unlock();
-#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache) {
SHM_PROTECT();
zend_file_cache_script_store(new_persistent_script, 1);
SHM_UNPROTECT();
}
-#endif
*from_shared_memory = 1;
return new_persistent_script;
CG(compiler_options) |= ZEND_COMPILE_DELAYED_BINDING;
CG(compiler_options) |= ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION;
CG(compiler_options) |= ZEND_COMPILE_IGNORE_OTHER_FILES;
-#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache) {
CG(compiler_options) |= ZEND_COMPILE_WITH_FILE_CACHE;
}
-#endif
op_array = *op_array_p = accelerator_orig_compile_file(file_handle, type);
CG(compiler_options) = orig_compiler_options;
} zend_catch {
return new_persistent_script;
}
-#ifdef HAVE_OPCACHE_FILE_CACHE
zend_op_array *file_cache_compile_file(zend_file_handle *file_handle, int type)
{
zend_persistent_script *persistent_script;
return op_array;
}
-#endif
/* zend_compile() replacement */
zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
if (!file_handle->filename || !ZCG(enabled) || !accel_startup_ok) {
/* The Accelerator is disabled, act as if without the Accelerator */
return accelerator_orig_compile_file(file_handle, type);
-#ifdef HAVE_OPCACHE_FILE_CACHE
} else if (file_cache_only) {
return file_cache_compile_file(file_handle, type);
-#endif
} else if ((!ZCG(counted) && !ZCSG(accelerator_enabled)) ||
(ZCSG(restart_in_progress) && accel_restart_is_active())) {
-#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache) {
return file_cache_compile_file(file_handle, type);
}
-#endif
return accelerator_orig_compile_file(file_handle, type);
}
*/
if (!ZCG(counted)) {
if (accel_activate_add() == FAILURE) {
-#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache) {
return file_cache_compile_file(file_handle, type);
}
-#endif
return accelerator_orig_compile_file(file_handle, type);
}
ZCG(counted) = 1;
}
}
-#ifdef HAVE_OPCACHE_FILE_CACHE
/* Check the second level cache */
if (!persistent_script && ZCG(accel_directives).file_cache) {
persistent_script = zend_file_cache_script_load(file_handle);
}
-#endif
/* If script was not found or invalidated by validate_timestamps */
if (!persistent_script) {
if (ZSMMG(memory_exhausted) || ZCSG(restart_pending)) {
SHM_PROTECT();
HANDLE_UNBLOCK_INTERRUPTIONS();
-#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache) {
return file_cache_compile_file(file_handle, type);
}
-#endif
return accelerator_orig_compile_file(file_handle, type);
}
static zend_string* persistent_zend_resolve_path(const char *filename, size_t filename_len)
{
if (ZCG(enabled) && accel_startup_ok &&
-#ifdef HAVE_OPCACHE_FILE_CACHE
!file_cache_only &&
-#endif
(ZCG(counted) || ZCSG(accelerator_enabled)) &&
!ZCSG(restart_in_progress)) {
ZCG(cwd_key_len) = 0;
ZCG(cwd_check) = 1;
-#ifdef HAVE_OPCACHE_FILE_CACHE
if (file_cache_only) {
return SUCCESS;
}
-#endif
#ifndef ZEND_WIN32
if (ZCG(accel_directives).validate_root) {
/********************************************/
/* End of non-SHM dependent initializations */
/********************************************/
-#ifdef HAVE_OPCACHE_FILE_CACHE
file_cache_only = ZCG(accel_directives).file_cache_only;
if (!file_cache_only) {
-#else
- if (1) {
-#endif
switch (zend_shared_alloc_startup(ZCG(accel_directives).memory_consumption)) {
case ALLOC_SUCCESS:
if (zend_accel_init_shm() == FAILURE) {
zend_shared_alloc_unlock();
SHM_PROTECT();
-#ifdef HAVE_OPCACHE_FILE_CACHE
} else if (!ZCG(accel_directives).file_cache) {
accel_startup_ok = 0;
zend_accel_error(ACCEL_LOG_FATAL, "opcache.file_cache_only is set without a proper setting of opcache.file_cache");
/* Init auto-global strings */
zend_accel_init_auto_globals();
-#endif
}
#if ENABLE_FILE_CACHE_FALLBACK
file_cache_fallback:
preload_shutdown();
}
-#ifdef HAVE_OPCACHE_FILE_CACHE
_file_cache_only = file_cache_only;
-#endif
accel_reset_pcre_cache();
}
}
-#ifdef HAVE_OPCACHE_FILE_CACHE
static ZEND_INI_MH(OnUpdateFileCache)
{
if (new_value) {
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
return SUCCESS;
}
-#endif
ZEND_INI_BEGIN()
STD_PHP_INI_BOOLEAN("opcache.enable" , "1", PHP_INI_ALL, OnEnable, enabled , zend_accel_globals, accel_globals)
STD_PHP_INI_ENTRY("opcache.mmap_base", NULL, PHP_INI_SYSTEM, OnUpdateString, accel_directives.mmap_base, zend_accel_globals, accel_globals)
#endif
-#ifdef HAVE_OPCACHE_FILE_CACHE
STD_PHP_INI_ENTRY("opcache.file_cache" , NULL , PHP_INI_SYSTEM, OnUpdateFileCache, accel_directives.file_cache, zend_accel_globals, accel_globals)
STD_PHP_INI_ENTRY("opcache.file_cache_only" , "0" , PHP_INI_SYSTEM, OnUpdateBool, accel_directives.file_cache_only, zend_accel_globals, accel_globals)
STD_PHP_INI_ENTRY("opcache.file_cache_consistency_checks" , "1" , PHP_INI_SYSTEM, OnUpdateBool, accel_directives.file_cache_consistency_checks, zend_accel_globals, accel_globals)
-#endif
#if ENABLE_FILE_CACHE_FALLBACK
STD_PHP_INI_ENTRY("opcache.file_cache_fallback" , "1" , PHP_INI_SYSTEM, OnUpdateBool, accel_directives.file_cache_fallback, zend_accel_globals, accel_globals)
#endif
{
zend_function *old_function;
if (ZCG(enabled) && accel_startup_ok && ZCG(accel_directives).file_override_enabled) {
-#ifdef HAVE_OPCACHE_FILE_CACHE
if (file_cache_only) {
zend_accel_error(ACCEL_LOG_WARNING, "file_override_enabled has no effect when file_cache_only is set");
return;
}
-#endif
/* override file_exists */
if ((old_function = zend_hash_str_find_ptr(CG(function_table), "file_exists", sizeof("file_exists")-1)) != NULL) {
orig_file_exists = old_function->internal_function.handler;
php_info_print_table_start();
if (ZCG(enabled) && accel_startup_ok &&
-#ifdef HAVE_OPCACHE_FILE_CACHE
((ZCG(counted) || ZCSG(accelerator_enabled)) || file_cache_only)
-#else
- (ZCG(counted) || ZCSG(accelerator_enabled))
-#endif
) {
php_info_print_table_row(2, "Opcode Caching", "Up and Running");
} else {
} else {
php_info_print_table_row(2, "Optimization", "Disabled");
}
-#ifdef HAVE_OPCACHE_FILE_CACHE
if (!file_cache_only) {
php_info_print_table_row(2, "SHM Cache", "Enabled");
} else {
php_info_print_table_row(2, "Startup", "OK");
}
} else
-#endif
if (ZCG(enabled)) {
if (!accel_startup_ok || zps_api_failure_reason) {
php_info_print_table_row(2, "Startup Failed", zps_api_failure_reason);
/* Trivia */
add_assoc_bool(return_value, "opcache_enabled", ZCG(enabled) && (ZCG(counted) || ZCSG(accelerator_enabled)));
-#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache) {
add_assoc_string(return_value, "file_cache", ZCG(accel_directives).file_cache);
}
add_assoc_bool(return_value, "file_cache_only", 1);
return;
}
-#endif
add_assoc_bool(return_value, "cache_full", ZSMMG(memory_exhausted));
add_assoc_bool(return_value, "restart_pending", ZCSG(restart_pending));
add_assoc_string(&directives, "opcache.lockfile_path", STRING_NOT_NULL(ZCG(accel_directives).lockfile_path));
#endif
-#ifdef HAVE_OPCACHE_FILE_CACHE
add_assoc_string(&directives, "opcache.file_cache", ZCG(accel_directives).file_cache ? ZCG(accel_directives).file_cache : "");
add_assoc_bool(&directives, "opcache.file_cache_only", ZCG(accel_directives).file_cache_only);
add_assoc_bool(&directives, "opcache.file_cache_consistency_checks", ZCG(accel_directives).file_cache_consistency_checks);
-#endif
add_assoc_zval(return_value, "directives", &directives);