PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/opcache - zend_accelerator_module.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 88 343 25.7 %
Date: 2014-07-21 Functions: 11 23 47.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend OPcache                                                         |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    |          Stanislav Malyshev <stas@zend.com>                          |
      18             :    |          Dmitry Stogov <dmitry@zend.com>                             |
      19             :    +----------------------------------------------------------------------+
      20             : */
      21             : 
      22             : #include <time.h>
      23             : 
      24             : #include "php.h"
      25             : #include "ZendAccelerator.h"
      26             : #include "zend_API.h"
      27             : #include "zend_shared_alloc.h"
      28             : #include "zend_accelerator_blacklist.h"
      29             : #include "php_ini.h"
      30             : #include "SAPI.h"
      31             : #if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
      32             : # include "zend_virtual_cwd.h"
      33             : #else
      34             : # include "TSRM/tsrm_virtual_cwd.h"
      35             : #endif
      36             : #include "ext/standard/info.h"
      37             : #include "ext/standard/php_filestat.h"
      38             : 
      39             : #define STRING_NOT_NULL(s) (NULL == (s)?"":s)
      40             : #define MIN_ACCEL_FILES 200
      41             : #define MAX_ACCEL_FILES 1000000
      42             : #define TOKENTOSTR(X) #X
      43             : 
      44             : static void (*orig_file_exists)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
      45             : static void (*orig_is_file)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
      46             : static void (*orig_is_readable)(INTERNAL_FUNCTION_PARAMETERS) = NULL;
      47             : 
      48             : ZEND_BEGIN_ARG_INFO(arginfo_opcache_none, 0)
      49             : ZEND_END_ARG_INFO()
      50             : 
      51             : ZEND_BEGIN_ARG_INFO_EX(arginfo_opcache_get_status, 0, 0, 0)
      52             :         ZEND_ARG_INFO(0, fetch_scripts)
      53             : ZEND_END_ARG_INFO()
      54             : 
      55             : ZEND_BEGIN_ARG_INFO_EX(arginfo_opcache_compile_file, 0, 0, 1)
      56             :         ZEND_ARG_INFO(0, file)
      57             : ZEND_END_ARG_INFO()
      58             : 
      59             : ZEND_BEGIN_ARG_INFO_EX(arginfo_opcache_invalidate, 0, 0, 1)
      60             :         ZEND_ARG_INFO(0, script)
      61             :         ZEND_ARG_INFO(0, force)
      62             : ZEND_END_ARG_INFO()
      63             : 
      64             : ZEND_BEGIN_ARG_INFO_EX(arginfo_opcache_is_script_cached, 0, 0, 1)
      65             :         ZEND_ARG_INFO(0, script)
      66             : ZEND_END_ARG_INFO()
      67             : 
      68             : /* User functions */
      69             : static ZEND_FUNCTION(opcache_reset);
      70             : static ZEND_FUNCTION(opcache_invalidate);
      71             : static ZEND_FUNCTION(opcache_is_script_cached);
      72             : 
      73             : /* Private functions */
      74             : static ZEND_FUNCTION(opcache_get_status);
      75             : static ZEND_FUNCTION(opcache_compile_file);
      76             : static ZEND_FUNCTION(opcache_get_configuration);
      77             : 
      78             : static zend_function_entry accel_functions[] = {
      79             :         /* User functions */
      80             :         ZEND_FE(opcache_reset,                                  arginfo_opcache_none)
      81             :         ZEND_FE(opcache_invalidate,                             arginfo_opcache_invalidate)
      82             :         ZEND_FE(opcache_compile_file,                   arginfo_opcache_compile_file)
      83             :         ZEND_FE(opcache_is_script_cached,               arginfo_opcache_is_script_cached)
      84             :         /* Private functions */
      85             :         ZEND_FE(opcache_get_configuration,              arginfo_opcache_none)
      86             :         ZEND_FE(opcache_get_status,                             arginfo_opcache_get_status)
      87             :         { NULL, NULL, NULL, 0, 0 }
      88             : };
      89             : 
      90           9 : static int validate_api_restriction(TSRMLS_D)
      91             : {
      92           9 :         if (ZCG(accel_directives).restrict_api && *ZCG(accel_directives).restrict_api) {
      93           0 :                 int len = strlen(ZCG(accel_directives).restrict_api);
      94             : 
      95           0 :                 if (!SG(request_info).path_translated ||
      96           0 :                     strlen(SG(request_info).path_translated) < len ||
      97           0 :                     memcmp(SG(request_info).path_translated, ZCG(accel_directives).restrict_api, len) != 0) {
      98           0 :                         zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " API is restricted by \"restrict_api\" configuration directive");
      99           0 :                         return 0;
     100             :                 }
     101             :         }       
     102           9 :         return 1;
     103             : }
     104             : 
     105       21140 : static ZEND_INI_MH(OnUpdateMemoryConsumption)
     106             : {
     107             :         long *p;
     108             :         long memsize;
     109             : #ifndef ZTS
     110       21140 :         char *base = (char *) mh_arg2;
     111             : #else
     112             :         char *base = (char *) ts_resource(*((int *) mh_arg2));
     113             : #endif
     114             : 
     115             :         /* keep the compiler happy */
     116             :         (void)entry; (void)new_value_length; (void)mh_arg2; (void)mh_arg3; (void)stage;
     117             : 
     118       21140 :         p = (long *) (base + (size_t)mh_arg1);
     119       21140 :         memsize = atoi(new_value);
     120             :         /* sanity check we must use at least 8 MB */
     121       21140 :         if (memsize < 8) {
     122           0 :                 const char *new_new_value = "8";
     123             :                 zend_ini_entry *ini_entry;
     124             : 
     125           0 :                 memsize = 8;
     126           0 :                 zend_accel_error(ACCEL_LOG_WARNING, "opcache.memory_consumption is set below the required 8MB.\n");
     127           0 :                 zend_accel_error(ACCEL_LOG_WARNING, ACCELERATOR_PRODUCT_NAME " will use the minimal 8MB configuration.\n");
     128             : 
     129           0 :                 if (zend_hash_find(EG(ini_directives),
     130             :                                         "opcache.memory_consumption",
     131             :                                         sizeof("opcache.memory_consumption"),
     132             :                                         (void *) &ini_entry) == FAILURE) {
     133           0 :                         return FAILURE;
     134             :                 }
     135             : 
     136           0 :                 ini_entry->value = strdup(new_new_value);
     137           0 :                 ini_entry->value_length = strlen(new_new_value);
     138             :         }
     139       21140 :         *p = memsize * (1024 * 1024);
     140       21140 :         return SUCCESS;
     141             : }
     142             : 
     143       21140 : static ZEND_INI_MH(OnUpdateMaxAcceleratedFiles)
     144             : {
     145             :         long *p;
     146             :         long size;
     147             : #ifndef ZTS
     148       21140 :         char *base = (char *) mh_arg2;
     149             : #else
     150             :         char *base = (char *) ts_resource(*((int *) mh_arg2));
     151             : #endif
     152             : 
     153             :         /* keep the compiler happy */
     154             :         (void)entry; (void)new_value_length; (void)mh_arg2; (void)mh_arg3; (void)stage;
     155             : 
     156       21140 :         p = (long *) (base + (size_t)mh_arg1);
     157       21140 :         size = atoi(new_value);
     158             :         /* sanity check we must use a value between MIN_ACCEL_FILES and MAX_ACCEL_FILES */
     159             : 
     160       21140 :         if (size < MIN_ACCEL_FILES || size > MAX_ACCEL_FILES) {
     161             :                 const char *new_new_value;
     162             :                 zend_ini_entry *ini_entry;
     163             : 
     164           0 :                 if (size < MIN_ACCEL_FILES) {
     165           0 :                         size = MIN_ACCEL_FILES;
     166           0 :                         new_new_value = TOKENTOSTR(MIN_ACCEL_FILES);
     167           0 :                         zend_accel_error(ACCEL_LOG_WARNING, "opcache.max_accelerated_files is set below the required minimum (%d).\n", MIN_ACCEL_FILES);
     168           0 :                         zend_accel_error(ACCEL_LOG_WARNING, ACCELERATOR_PRODUCT_NAME " will use the minimal configuration.\n");
     169             :                 }
     170           0 :                 if (size > MAX_ACCEL_FILES) {
     171           0 :                         size = MAX_ACCEL_FILES;
     172           0 :                         new_new_value = TOKENTOSTR(MAX_ACCEL_FILES);
     173           0 :                         zend_accel_error(ACCEL_LOG_WARNING, "opcache.max_accelerated_files is set above the limit (%d).\n", MAX_ACCEL_FILES);
     174           0 :                         zend_accel_error(ACCEL_LOG_WARNING, ACCELERATOR_PRODUCT_NAME " will use the maximal configuration.\n");
     175             :                 }
     176           0 :                 if (zend_hash_find(EG(ini_directives),
     177             :                                         "opcache.max_accelerated_files",
     178             :                                         sizeof("opcache.max_accelerated_files"),
     179             :                                         (void *) &ini_entry) == FAILURE) {
     180           0 :                         return FAILURE;
     181             :                 }
     182           0 :                 ini_entry->value = strdup(new_new_value);
     183           0 :                 ini_entry->value_length = strlen(new_new_value);
     184             :         }
     185       21140 :         *p = size;
     186       21140 :         return SUCCESS;
     187             : }
     188             : 
     189       21140 : static ZEND_INI_MH(OnUpdateMaxWastedPercentage)
     190             : {
     191             :         double *p;
     192             :         long percentage;
     193             : #ifndef ZTS
     194       21140 :         char *base = (char *) mh_arg2;
     195             : #else
     196             :         char *base = (char *) ts_resource(*((int *) mh_arg2));
     197             : #endif
     198             : 
     199             :         /* keep the compiler happy */
     200             :         (void)entry; (void)new_value_length; (void)mh_arg2; (void)mh_arg3; (void)stage;
     201             : 
     202       21140 :         p = (double *) (base + (size_t)mh_arg1);
     203       21140 :         percentage = atoi(new_value);
     204             : 
     205       21140 :         if (percentage <= 0 || percentage > 50) {
     206           0 :                 const char *new_new_value = "5";
     207             :                 zend_ini_entry *ini_entry;
     208             : 
     209           0 :                 percentage = 5;
     210           0 :                 zend_accel_error(ACCEL_LOG_WARNING, "opcache.max_wasted_percentage must be set between 1 and 50.\n");
     211           0 :                 zend_accel_error(ACCEL_LOG_WARNING, ACCELERATOR_PRODUCT_NAME " will use 5%.\n");
     212           0 :                 if (zend_hash_find(EG(ini_directives),
     213             :                                         "opcache.max_wasted_percentage",
     214             :                                         sizeof("opcache.max_wasted_percentage"),
     215             :                                         (void *) &ini_entry) == FAILURE) {
     216           0 :                         return FAILURE;
     217             :                 }
     218           0 :                 ini_entry->value = strdup(new_new_value);
     219           0 :                 ini_entry->value_length = strlen(new_new_value);
     220             :         }
     221       21140 :         *p = (double)percentage / 100.0;
     222       21140 :         return SUCCESS;
     223             : }
     224             : 
     225       21140 : static ZEND_INI_MH(OnEnable)
     226             : {
     227       21140 :         if (stage == ZEND_INI_STAGE_STARTUP ||
     228             :             stage == ZEND_INI_STAGE_SHUTDOWN ||
     229             :             stage == ZEND_INI_STAGE_DEACTIVATE) {
     230       21140 :                 return OnUpdateBool(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
     231             :         } else {
     232             :                 /* It may be only temporary disabled */
     233             :                 zend_bool *p;
     234             : #ifndef ZTS
     235           0 :                 char *base = (char *) mh_arg2;
     236             : #else
     237             :                 char *base = (char *) ts_resource(*((int *) mh_arg2));
     238             : #endif
     239             : 
     240           0 :                 p = (zend_bool *) (base+(size_t) mh_arg1);
     241           0 :                 if ((new_value_length == 2 && strcasecmp("on", new_value) == 0) ||
     242           0 :                     (new_value_length == 3 && strcasecmp("yes", new_value) == 0) ||
     243           0 :                     (new_value_length == 4 && strcasecmp("true", new_value) == 0) ||
     244           0 :                         atoi(new_value) != 0) {
     245           0 :                         zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " can't be temporary enabled (it may be only disabled till the end of request)");
     246           0 :                         return FAILURE;
     247             :                 } else {
     248           0 :                         *p = 0;
     249           0 :                         return SUCCESS;
     250             :                 }
     251             :         }
     252             : }
     253             : 
     254             : ZEND_INI_BEGIN()
     255             :     STD_PHP_INI_BOOLEAN("opcache.enable"             , "1", PHP_INI_ALL,    OnEnable,     enabled                             , zend_accel_globals, accel_globals)
     256             :         STD_PHP_INI_BOOLEAN("opcache.use_cwd"            , "1", PHP_INI_SYSTEM, OnUpdateBool, accel_directives.use_cwd            , zend_accel_globals, accel_globals)
     257             :         STD_PHP_INI_BOOLEAN("opcache.validate_timestamps", "1", PHP_INI_ALL   , OnUpdateBool, accel_directives.validate_timestamps, zend_accel_globals, accel_globals)
     258             :         STD_PHP_INI_BOOLEAN("opcache.inherited_hack"     , "1", PHP_INI_SYSTEM, OnUpdateBool, accel_directives.inherited_hack     , zend_accel_globals, accel_globals)
     259             :         STD_PHP_INI_BOOLEAN("opcache.dups_fix"           , "0", PHP_INI_ALL   , OnUpdateBool, accel_directives.ignore_dups        , zend_accel_globals, accel_globals)
     260             :         STD_PHP_INI_BOOLEAN("opcache.revalidate_path"    , "0", PHP_INI_ALL   , OnUpdateBool, accel_directives.revalidate_path    , zend_accel_globals, accel_globals)
     261             : 
     262             :         STD_PHP_INI_ENTRY("opcache.log_verbosity_level"   , "1"   , PHP_INI_SYSTEM, OnUpdateLong, accel_directives.log_verbosity_level,       zend_accel_globals, accel_globals)
     263             :         STD_PHP_INI_ENTRY("opcache.memory_consumption"    , "64"  , PHP_INI_SYSTEM, OnUpdateMemoryConsumption,    accel_directives.memory_consumption,        zend_accel_globals, accel_globals)
     264             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     265             :         STD_PHP_INI_ENTRY("opcache.interned_strings_buffer", "4"  , PHP_INI_SYSTEM, OnUpdateLong,                 accel_directives.interned_strings_buffer,   zend_accel_globals, accel_globals)
     266             : #endif
     267             :         STD_PHP_INI_ENTRY("opcache.max_accelerated_files" , "2000", PHP_INI_SYSTEM, OnUpdateMaxAcceleratedFiles,     accel_directives.max_accelerated_files,     zend_accel_globals, accel_globals)
     268             :         STD_PHP_INI_ENTRY("opcache.max_wasted_percentage" , "5"   , PHP_INI_SYSTEM, OnUpdateMaxWastedPercentage,     accel_directives.max_wasted_percentage,     zend_accel_globals, accel_globals)
     269             :         STD_PHP_INI_ENTRY("opcache.consistency_checks"    , "0"   , PHP_INI_ALL   , OnUpdateLong,                accel_directives.consistency_checks,        zend_accel_globals, accel_globals)
     270             :         STD_PHP_INI_ENTRY("opcache.force_restart_timeout" , "180" , PHP_INI_SYSTEM, OnUpdateLong,                accel_directives.force_restart_timeout,     zend_accel_globals, accel_globals)
     271             :         STD_PHP_INI_ENTRY("opcache.revalidate_freq"       , "2"   , PHP_INI_ALL   , OnUpdateLong,                accel_directives.revalidate_freq,           zend_accel_globals, accel_globals)
     272             :         STD_PHP_INI_ENTRY("opcache.file_update_protection", "2"   , PHP_INI_ALL   , OnUpdateLong,                accel_directives.file_update_protection,    zend_accel_globals, accel_globals)
     273             :         STD_PHP_INI_ENTRY("opcache.preferred_memory_model", ""    , PHP_INI_SYSTEM, OnUpdateStringUnempty,       accel_directives.memory_model,              zend_accel_globals, accel_globals)
     274             :         STD_PHP_INI_ENTRY("opcache.blacklist_filename"    , ""    , PHP_INI_SYSTEM, OnUpdateString,              accel_directives.user_blacklist_filename,   zend_accel_globals, accel_globals)
     275             :         STD_PHP_INI_ENTRY("opcache.max_file_size"         , "0"   , PHP_INI_SYSTEM, OnUpdateLong,                accel_directives.max_file_size,             zend_accel_globals, accel_globals)
     276             : 
     277             :         STD_PHP_INI_ENTRY("opcache.protect_memory"        , "0"  , PHP_INI_SYSTEM, OnUpdateBool,                  accel_directives.protect_memory,            zend_accel_globals, accel_globals)
     278             :         STD_PHP_INI_ENTRY("opcache.save_comments"         , "1"  , PHP_INI_SYSTEM, OnUpdateBool,                  accel_directives.save_comments,             zend_accel_globals, accel_globals)
     279             :         STD_PHP_INI_ENTRY("opcache.load_comments"         , "1"  , PHP_INI_ALL,    OnUpdateBool,                  accel_directives.load_comments,             zend_accel_globals, accel_globals)
     280             :         STD_PHP_INI_ENTRY("opcache.fast_shutdown"         , "0"  , PHP_INI_SYSTEM, OnUpdateBool,                  accel_directives.fast_shutdown,             zend_accel_globals, accel_globals)
     281             : 
     282             :         STD_PHP_INI_ENTRY("opcache.optimization_level"    , DEFAULT_OPTIMIZATION_LEVEL , PHP_INI_SYSTEM, OnUpdateLong, accel_directives.optimization_level,   zend_accel_globals, accel_globals)
     283             :         STD_PHP_INI_BOOLEAN("opcache.enable_file_override"    , "0"   , PHP_INI_SYSTEM, OnUpdateBool,              accel_directives.file_override_enabled,     zend_accel_globals, accel_globals)
     284             :         STD_PHP_INI_BOOLEAN("opcache.enable_cli"             , "0"   , PHP_INI_SYSTEM, OnUpdateBool,              accel_directives.enable_cli,                zend_accel_globals, accel_globals)
     285             :         STD_PHP_INI_ENTRY("opcache.error_log"                , ""    , PHP_INI_SYSTEM, OnUpdateString,               accel_directives.error_log,                 zend_accel_globals, accel_globals)
     286             :         STD_PHP_INI_ENTRY("opcache.restrict_api"             , ""    , PHP_INI_SYSTEM, OnUpdateString,               accel_directives.restrict_api,              zend_accel_globals, accel_globals)
     287             : 
     288             : #ifdef ZEND_WIN32
     289             :         STD_PHP_INI_ENTRY("opcache.mmap_base", NULL, PHP_INI_SYSTEM,  OnUpdateString,                              accel_directives.mmap_base,                 zend_accel_globals, accel_globals)
     290             : #endif
     291             : ZEND_INI_END()
     292             : 
     293             : #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
     294             : 
     295             : #undef  EX
     296             : #define EX(element) execute_data->element
     297             : #define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset))
     298             : 
     299             : static int ZEND_DECLARE_INHERITED_CLASS_DELAYED_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
     300             : {
     301             :         zend_class_entry **pce, **pce_orig;
     302             : 
     303             :         if (zend_hash_find(EG(class_table), Z_STRVAL(EX(opline)->op2.u.constant), Z_STRLEN(EX(opline)->op2.u.constant) + 1, (void **)&pce) == FAILURE ||
     304             :             (zend_hash_find(EG(class_table), Z_STRVAL(EX(opline)->op1.u.constant), Z_STRLEN(EX(opline)->op1.u.constant), (void**)&pce_orig) == SUCCESS &&
     305             :              *pce != *pce_orig)) {
     306             :                 do_bind_inherited_class(EX(opline), EG(class_table), EX_T(EX(opline)->extended_value).class_entry, 0 TSRMLS_CC);
     307             :         }
     308             :         EX(opline)++;
     309             :         return ZEND_USER_OPCODE_CONTINUE;
     310             : }
     311             : #endif
     312             : 
     313           0 : static int filename_is_in_cache(char *filename, int filename_len TSRMLS_DC)
     314             : {
     315             :         char *key;
     316             :         int key_length;
     317           0 :         zend_file_handle handle = {0};
     318             :         zend_persistent_script *persistent_script;
     319             : 
     320           0 :         handle.filename = filename;
     321           0 :         handle.type = ZEND_HANDLE_FILENAME;
     322             : 
     323           0 :         if (IS_ABSOLUTE_PATH(filename, filename_len)) {
     324           0 :                 persistent_script = zend_accel_hash_find(&ZCSG(hash), filename, filename_len + 1);
     325           0 :                 if (persistent_script) {
     326           0 :                         return !persistent_script->corrupted &&
     327           0 :                                 validate_timestamp_and_record(persistent_script, &handle TSRMLS_CC) == SUCCESS;
     328             :                 }
     329             :         }
     330             : 
     331           0 :         if ((key = accel_make_persistent_key_ex(&handle, filename_len, &key_length TSRMLS_CC)) != NULL) {
     332           0 :                 persistent_script = zend_accel_hash_find(&ZCSG(hash), key, key_length + 1);
     333           0 :                 return persistent_script && !persistent_script->corrupted &&
     334           0 :                         validate_timestamp_and_record(persistent_script, &handle TSRMLS_CC) == SUCCESS;
     335             :         }
     336             : 
     337           0 :         return 0;
     338             : }
     339             : 
     340           0 : static int accel_file_in_cache(INTERNAL_FUNCTION_PARAMETERS)
     341             : {
     342             :         zval **zfilename;
     343             : 
     344           0 :         if (ZEND_NUM_ARGS() != 1 ||
     345           0 :             zend_get_parameters_array_ex(1, &zfilename) == FAILURE ||
     346           0 :             Z_TYPE_PP(zfilename) != IS_STRING ||
     347           0 :             Z_STRLEN_PP(zfilename) == 0) {
     348           0 :                 return 0;
     349             :         }
     350           0 :         return filename_is_in_cache(Z_STRVAL_PP(zfilename), Z_STRLEN_PP(zfilename) TSRMLS_CC);
     351             : }
     352             : 
     353           0 : static void accel_file_exists(INTERNAL_FUNCTION_PARAMETERS)
     354             : {
     355           0 :         if (accel_file_in_cache(INTERNAL_FUNCTION_PARAM_PASSTHRU)) {
     356           0 :                 RETURN_TRUE;
     357             :         } else {
     358           0 :                 orig_file_exists(INTERNAL_FUNCTION_PARAM_PASSTHRU);
     359             :         }
     360             : }
     361             : 
     362           0 : static void accel_is_file(INTERNAL_FUNCTION_PARAMETERS)
     363             : {
     364           0 :         if (accel_file_in_cache(INTERNAL_FUNCTION_PARAM_PASSTHRU)) {
     365           0 :                 RETURN_TRUE;
     366             :         } else {
     367           0 :                 orig_is_file(INTERNAL_FUNCTION_PARAM_PASSTHRU);
     368             :         }
     369             : }
     370             : 
     371           0 : static void accel_is_readable(INTERNAL_FUNCTION_PARAMETERS)
     372             : {
     373           0 :         if (accel_file_in_cache(INTERNAL_FUNCTION_PARAM_PASSTHRU)) {
     374           0 :                 RETURN_TRUE;
     375             :         } else {
     376           0 :                 orig_is_readable(INTERNAL_FUNCTION_PARAM_PASSTHRU);
     377             :         }
     378             : }
     379             : 
     380       21140 : static ZEND_MINIT_FUNCTION(zend_accelerator)
     381             : {
     382             :         (void)type; /* keep the compiler happy */
     383             : 
     384       21140 :         REGISTER_INI_ENTRIES();
     385             : #if ZEND_EXTENSION_API_NO < PHP_5_3_X_API_NO
     386             :         zend_set_user_opcode_handler(ZEND_DECLARE_INHERITED_CLASS_DELAYED, ZEND_DECLARE_INHERITED_CLASS_DELAYED_HANDLER);
     387             : #endif
     388       21140 :         return SUCCESS;
     389             : }
     390             : 
     391         368 : void zend_accel_override_file_functions(TSRMLS_D)
     392             : {
     393             :         zend_function *old_function;
     394         368 :         if (ZCG(enabled) && accel_startup_ok && ZCG(accel_directives).file_override_enabled) {
     395             :                 /* override file_exists */
     396           0 :                 if (zend_hash_find(CG(function_table), "file_exists", sizeof("file_exists"), (void **)&old_function) == SUCCESS) {
     397           0 :                         orig_file_exists = old_function->internal_function.handler;
     398           0 :                         old_function->internal_function.handler = accel_file_exists;
     399             :                 }
     400           0 :                 if (zend_hash_find(CG(function_table), "is_file", sizeof("is_file"), (void **)&old_function) == SUCCESS) {
     401           0 :                         orig_is_file = old_function->internal_function.handler;
     402           0 :                         old_function->internal_function.handler = accel_is_file;
     403             :                 }
     404           0 :                 if (zend_hash_find(CG(function_table), "is_readable", sizeof("is_readable"), (void **)&old_function) == SUCCESS) {
     405           0 :                         orig_is_readable = old_function->internal_function.handler;
     406           0 :                         old_function->internal_function.handler = accel_is_readable;
     407             :                 }
     408             :         }
     409         368 : }
     410             : 
     411       21138 : static ZEND_MSHUTDOWN_FUNCTION(zend_accelerator)
     412             : {
     413             :         (void)type; /* keep the compiler happy */
     414             : 
     415       21138 :         UNREGISTER_INI_ENTRIES();
     416       21138 :         accel_shutdown(TSRMLS_C);
     417       21138 :         return SUCCESS;
     418             : }
     419             : 
     420         149 : void zend_accel_info(ZEND_MODULE_INFO_FUNC_ARGS)
     421             : {
     422         149 :         php_info_print_table_start();
     423             : 
     424         150 :         if (ZCG(enabled) && accel_startup_ok && (ZCG(counted) || ZCSG(accelerator_enabled))) {
     425           1 :                 php_info_print_table_row(2, "Opcode Caching", "Up and Running");
     426             :         } else {
     427         148 :                 php_info_print_table_row(2, "Opcode Caching", "Disabled");
     428             :         }
     429         150 :         if (ZCG(enabled) && accel_startup_ok && ZCSG(accelerator_enabled) && ZCG(accel_directives).optimization_level) {
     430           1 :                 php_info_print_table_row(2, "Optimization", "Enabled");
     431             :         } else {
     432         148 :                 php_info_print_table_row(2, "Optimization", "Disabled");
     433             :         }
     434         149 :         if (ZCG(enabled)) {
     435         297 :                 if (!accel_startup_ok || zps_api_failure_reason) {
     436         148 :                         php_info_print_table_row(2, "Startup Failed", zps_api_failure_reason);
     437             :                 } else {
     438             :                         char buf[32];
     439           1 :                         php_info_print_table_row(2, "Startup", "OK");
     440           1 :                         php_info_print_table_row(2, "Shared memory model", zend_accel_get_shared_model());
     441           1 :                         snprintf(buf, sizeof(buf), "%ld", ZCSG(hits));
     442           1 :                         php_info_print_table_row(2, "Cache hits", buf);
     443           1 :                         snprintf(buf, sizeof(buf), "%ld", ZSMMG(memory_exhausted)?ZCSG(misses):ZCSG(misses)-ZCSG(blacklist_misses));
     444           1 :                         php_info_print_table_row(2, "Cache misses", buf);
     445           1 :                         snprintf(buf, sizeof(buf), "%ld", ZCG(accel_directives).memory_consumption-zend_shared_alloc_get_free_memory()-ZSMMG(wasted_shared_memory));
     446           1 :                         php_info_print_table_row(2, "Used memory", buf);
     447           1 :                         snprintf(buf, sizeof(buf), "%ld", zend_shared_alloc_get_free_memory());
     448           1 :                         php_info_print_table_row(2, "Free memory", buf);
     449           1 :                         snprintf(buf, sizeof(buf), "%ld", ZSMMG(wasted_shared_memory));
     450           1 :                         php_info_print_table_row(2, "Wasted memory", buf);
     451             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     452           1 :                         if (ZCSG(interned_strings_start) && ZCSG(interned_strings_end) && ZCSG(interned_strings_top)) {
     453           1 :                                 snprintf(buf, sizeof(buf), "%ld", ZCSG(interned_strings_top) - ZCSG(interned_strings_start));
     454           1 :                                 php_info_print_table_row(2, "Interned Strings Used memory", buf);
     455           1 :                                 snprintf(buf, sizeof(buf), "%ld", ZCSG(interned_strings_end) - ZCSG(interned_strings_top));
     456           1 :                                 php_info_print_table_row(2, "Interned Strings Free memory", buf);
     457             :                         }
     458             : #endif
     459           1 :                         snprintf(buf, sizeof(buf), "%ld", ZCSG(hash).num_direct_entries);
     460           1 :                         php_info_print_table_row(2, "Cached scripts", buf);
     461           1 :                         snprintf(buf, sizeof(buf), "%ld", ZCSG(hash).num_entries);
     462           1 :                         php_info_print_table_row(2, "Cached keys", buf);
     463           1 :                         snprintf(buf, sizeof(buf), "%ld", ZCSG(hash).max_num_entries);
     464           1 :                         php_info_print_table_row(2, "Max keys", buf);
     465           1 :                         snprintf(buf, sizeof(buf), "%ld", ZCSG(oom_restarts));
     466           1 :                         php_info_print_table_row(2, "OOM restarts", buf);
     467           1 :                         snprintf(buf, sizeof(buf), "%ld", ZCSG(hash_restarts));
     468           1 :                         php_info_print_table_row(2, "Hash keys restarts", buf);
     469           1 :                         snprintf(buf, sizeof(buf), "%ld", ZCSG(manual_restarts));
     470           1 :                         php_info_print_table_row(2, "Manual restarts", buf);
     471             :                 }
     472             :         }
     473             : 
     474         149 :         php_info_print_table_end();
     475         149 :         DISPLAY_INI_ENTRIES();
     476         149 : }
     477             : 
     478             : static zend_module_entry accel_module_entry = {
     479             :         STANDARD_MODULE_HEADER,
     480             :         ACCELERATOR_PRODUCT_NAME,
     481             :         accel_functions,
     482             :         ZEND_MINIT(zend_accelerator),
     483             :         ZEND_MSHUTDOWN(zend_accelerator),
     484             :         NULL,
     485             :         NULL,
     486             :         zend_accel_info,
     487             :     ACCELERATOR_VERSION "FE",
     488             :         STANDARD_MODULE_PROPERTIES
     489             : };
     490             : 
     491             : #if ZEND_EXTENSION_API_NO > PHP_5_6_X_API_NO
     492       21140 : int start_accel_module(TSRMLS_D)
     493             : {
     494       21140 :         return zend_startup_module(&accel_module_entry TSRMLS_CC);
     495             : }
     496             : #else
     497             : int start_accel_module(void)
     498             : {
     499             :         return zend_startup_module(&accel_module_entry);
     500             : }
     501             : #endif
     502             : 
     503             : /* {{{ proto array accelerator_get_scripts()
     504             :    Get the scripts which are accelerated by ZendAccelerator */
     505           0 : static zval* accelerator_get_scripts(TSRMLS_D)
     506             : {
     507             :         uint i;
     508             :         zval *return_value,*persistent_script_report;
     509             :         zend_accel_hash_entry *cache_entry;
     510             :         struct tm *ta;
     511             :         struct timeval exec_time;
     512             :         struct timeval fetch_time;
     513             : 
     514           0 :         if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled) || accelerator_shm_read_lock(TSRMLS_C) != SUCCESS) {
     515           0 :                 return 0;
     516             :         }
     517             : 
     518           0 :         MAKE_STD_ZVAL(return_value);
     519           0 :         array_init(return_value);
     520           0 :         for (i = 0; i<ZCSG(hash).max_num_entries; i++) {
     521           0 :                 for (cache_entry = ZCSG(hash).hash_table[i]; cache_entry; cache_entry = cache_entry->next) {
     522             :                         zend_persistent_script *script;
     523             :                         char *str;
     524             :                         size_t len;
     525             : 
     526           0 :                         if (cache_entry->indirect) continue;
     527             : 
     528           0 :                         script = (zend_persistent_script *)cache_entry->data;
     529             : 
     530           0 :                         MAKE_STD_ZVAL(persistent_script_report);
     531           0 :                         array_init(persistent_script_report);
     532           0 :                         add_assoc_stringl(persistent_script_report, "full_path", script->full_path, script->full_path_len, 1);
     533           0 :                         add_assoc_long(persistent_script_report, "hits", script->dynamic_members.hits);
     534           0 :                         add_assoc_long(persistent_script_report, "memory_consumption", script->dynamic_members.memory_consumption);
     535           0 :                         ta = localtime(&script->dynamic_members.last_used);
     536           0 :                         str = asctime(ta);
     537           0 :                         len = strlen(str);
     538           0 :                         if (len > 0 && str[len - 1] == '\n') len--;
     539           0 :                         add_assoc_stringl(persistent_script_report, "last_used", str, len, 1);
     540           0 :                         add_assoc_long(persistent_script_report, "last_used_timestamp", script->dynamic_members.last_used);
     541           0 :                         if (ZCG(accel_directives).validate_timestamps) {
     542           0 :                                 add_assoc_long(persistent_script_report, "timestamp", (long)script->timestamp);
     543             :                         }
     544           0 :                         timerclear(&exec_time);
     545           0 :                         timerclear(&fetch_time);
     546             : 
     547           0 :                         zend_hash_update(return_value->value.ht, cache_entry->key, cache_entry->key_length, &persistent_script_report, sizeof(zval *), NULL);
     548             :                 }
     549             :         }
     550           0 :         accelerator_shm_read_unlock(TSRMLS_C);
     551             : 
     552           0 :         return return_value;
     553             : }
     554             : 
     555             : /* {{{ proto array accelerator_get_status([bool fetch_scripts])
     556             :    Obtain statistics information regarding code acceleration */
     557           9 : static ZEND_FUNCTION(opcache_get_status)
     558             : {
     559             :         long reqs;
     560             :         zval *memory_usage,*statistics,*scripts;
     561           9 :         zend_bool fetch_scripts = 1;
     562             : 
     563             :         /* keep the compiler happy */
     564             :         (void)ht; (void)return_value_ptr; (void)this_ptr; (void)return_value_used;
     565             : 
     566           9 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &fetch_scripts) == FAILURE) {
     567           0 :                 return;
     568             :         }
     569             :         
     570           9 :         if (!validate_api_restriction(TSRMLS_C)) {
     571           0 :                 RETURN_FALSE;
     572             :         }
     573             : 
     574           9 :         if (!accel_startup_ok) {
     575           9 :                 RETURN_FALSE;
     576             :         }
     577             : 
     578           0 :         array_init(return_value);
     579             : 
     580             :         /* Trivia */
     581           0 :         add_assoc_bool(return_value, "opcache_enabled", ZCG(enabled) && (ZCG(counted) || ZCSG(accelerator_enabled)));
     582           0 :         add_assoc_bool(return_value, "cache_full", ZSMMG(memory_exhausted));
     583           0 :         add_assoc_bool(return_value, "restart_pending", ZCSG(restart_pending));
     584           0 :         add_assoc_bool(return_value, "restart_in_progress", ZCSG(restart_in_progress));
     585             : 
     586             :         /* Memory usage statistics */
     587           0 :         MAKE_STD_ZVAL(memory_usage);
     588           0 :         array_init(memory_usage);
     589           0 :         add_assoc_long(memory_usage, "used_memory", ZCG(accel_directives).memory_consumption-zend_shared_alloc_get_free_memory()-ZSMMG(wasted_shared_memory));
     590           0 :         add_assoc_long(memory_usage, "free_memory", zend_shared_alloc_get_free_memory());
     591           0 :         add_assoc_long(memory_usage, "wasted_memory", ZSMMG(wasted_shared_memory));
     592           0 :         add_assoc_double(memory_usage, "current_wasted_percentage", (((double) ZSMMG(wasted_shared_memory))/ZCG(accel_directives).memory_consumption)*100.0);
     593           0 :         add_assoc_zval(return_value, "memory_usage", memory_usage);
     594             : 
     595             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     596           0 :         if (ZCSG(interned_strings_start) && ZCSG(interned_strings_end) && ZCSG(interned_strings_top)) {
     597             :                 zval *interned_strings_usage;
     598             : 
     599           0 :                 MAKE_STD_ZVAL(interned_strings_usage);
     600           0 :                 array_init(interned_strings_usage);
     601           0 :                 add_assoc_long(interned_strings_usage, "buffer_size", ZCSG(interned_strings_end) - ZCSG(interned_strings_start));
     602           0 :                 add_assoc_long(interned_strings_usage, "used_memory", ZCSG(interned_strings_top) - ZCSG(interned_strings_start));
     603           0 :                 add_assoc_long(interned_strings_usage, "free_memory", ZCSG(interned_strings_end) - ZCSG(interned_strings_top));
     604           0 :                 add_assoc_long(interned_strings_usage, "number_of_strings", ZCSG(interned_strings).nNumOfElements);
     605           0 :                 add_assoc_zval(return_value, "interned_strings_usage", interned_strings_usage);
     606             :         }
     607             : #endif
     608             :         
     609             :         /* Accelerator statistics */
     610           0 :         MAKE_STD_ZVAL(statistics);
     611           0 :         array_init(statistics);
     612           0 :         add_assoc_long(statistics, "num_cached_scripts", ZCSG(hash).num_direct_entries);
     613           0 :         add_assoc_long(statistics, "num_cached_keys",    ZCSG(hash).num_entries);
     614           0 :         add_assoc_long(statistics, "max_cached_keys",    ZCSG(hash).max_num_entries);
     615           0 :         add_assoc_long(statistics, "hits", ZCSG(hits));
     616           0 :         add_assoc_long(statistics, "start_time", ZCSG(start_time));
     617           0 :         add_assoc_long(statistics, "last_restart_time", ZCSG(last_restart_time));
     618           0 :         add_assoc_long(statistics, "oom_restarts", ZCSG(oom_restarts));
     619           0 :         add_assoc_long(statistics, "hash_restarts", ZCSG(hash_restarts));
     620           0 :         add_assoc_long(statistics, "manual_restarts", ZCSG(manual_restarts));
     621           0 :         add_assoc_long(statistics, "misses", ZSMMG(memory_exhausted)?ZCSG(misses):ZCSG(misses)-ZCSG(blacklist_misses));
     622           0 :         add_assoc_long(statistics, "blacklist_misses", ZCSG(blacklist_misses));
     623           0 :         reqs = ZCSG(hits)+ZCSG(misses);
     624           0 :         add_assoc_double(statistics, "blacklist_miss_ratio", reqs?(((double) ZCSG(blacklist_misses))/reqs)*100.0:0);
     625           0 :         add_assoc_double(statistics, "opcache_hit_rate", reqs?(((double) ZCSG(hits))/reqs)*100.0:0);
     626           0 :         add_assoc_zval(return_value, "opcache_statistics", statistics);
     627             : 
     628           0 :         if (fetch_scripts) {
     629             :                 /* accelerated scripts */
     630           0 :                 scripts = accelerator_get_scripts(TSRMLS_C);
     631           0 :                 if (scripts) {
     632           0 :                         add_assoc_zval(return_value, "scripts", scripts);
     633             :                 }
     634             :         }
     635             : }
     636             : 
     637           0 : static int add_blacklist_path(zend_blacklist_entry *p, zval *return_value TSRMLS_DC)
     638             : {
     639           0 :         add_next_index_stringl(return_value, p->path, p->path_length, 1);
     640           0 :         return 0;
     641             : }
     642             : 
     643             : /* {{{ proto array accelerator_get_configuration()
     644             :    Obtain configuration information */
     645           0 : static ZEND_FUNCTION(opcache_get_configuration)
     646             : {
     647             :         zval *directives,*version,*blacklist;
     648             : 
     649             :         /* keep the compiler happy */
     650             :         (void)ht; (void)return_value_ptr; (void)this_ptr; (void)return_value_used;
     651             : 
     652             : #if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
     653           0 :         if (zend_parse_parameters_none() == FAILURE) {
     654           0 :                 RETURN_FALSE;
     655             :         }
     656             : #endif
     657             : 
     658           0 :         if (!validate_api_restriction(TSRMLS_C)) {
     659           0 :                 RETURN_FALSE;
     660             :         }
     661             : 
     662           0 :         array_init(return_value);
     663             : 
     664             :         /* directives */
     665           0 :         MAKE_STD_ZVAL(directives);
     666           0 :         array_init(directives);
     667           0 :         add_assoc_bool(directives, "opcache.enable",              ZCG(enabled));
     668           0 :         add_assoc_bool(directives, "opcache.enable_cli",          ZCG(accel_directives).enable_cli);
     669           0 :         add_assoc_bool(directives, "opcache.use_cwd",             ZCG(accel_directives).use_cwd);
     670           0 :         add_assoc_bool(directives, "opcache.validate_timestamps", ZCG(accel_directives).validate_timestamps);
     671           0 :         add_assoc_bool(directives, "opcache.inherited_hack",      ZCG(accel_directives).inherited_hack);
     672           0 :         add_assoc_bool(directives, "opcache.dups_fix",            ZCG(accel_directives).ignore_dups);
     673           0 :         add_assoc_bool(directives, "opcache.revalidate_path",     ZCG(accel_directives).revalidate_path);
     674             : 
     675           0 :         add_assoc_long(directives,   "opcache.log_verbosity_level",    ZCG(accel_directives).log_verbosity_level);
     676           0 :         add_assoc_long(directives,       "opcache.memory_consumption",     ZCG(accel_directives).memory_consumption);
     677             : #if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
     678           0 :         add_assoc_long(directives,       "opcache.interned_strings_buffer",ZCG(accel_directives).interned_strings_buffer);
     679             : #endif
     680           0 :         add_assoc_long(directives,       "opcache.max_accelerated_files",  ZCG(accel_directives).max_accelerated_files);
     681           0 :         add_assoc_double(directives, "opcache.max_wasted_percentage",  ZCG(accel_directives).max_wasted_percentage);
     682           0 :         add_assoc_long(directives,       "opcache.consistency_checks",     ZCG(accel_directives).consistency_checks);
     683           0 :         add_assoc_long(directives,       "opcache.force_restart_timeout",  ZCG(accel_directives).force_restart_timeout);
     684           0 :         add_assoc_long(directives,       "opcache.revalidate_freq",        ZCG(accel_directives).revalidate_freq);
     685           0 :         add_assoc_string(directives, "opcache.preferred_memory_model", STRING_NOT_NULL(ZCG(accel_directives).memory_model), 1);
     686           0 :         add_assoc_string(directives, "opcache.blacklist_filename",     STRING_NOT_NULL(ZCG(accel_directives).user_blacklist_filename), 1);
     687           0 :         add_assoc_long(directives,   "opcache.max_file_size",          ZCG(accel_directives).max_file_size);
     688           0 :         add_assoc_string(directives, "opcache.error_log",              STRING_NOT_NULL(ZCG(accel_directives).error_log), 1);
     689             : 
     690           0 :         add_assoc_bool(directives,   "opcache.protect_memory",         ZCG(accel_directives).protect_memory);
     691           0 :         add_assoc_bool(directives,   "opcache.save_comments",          ZCG(accel_directives).save_comments);
     692           0 :         add_assoc_bool(directives,   "opcache.load_comments",          ZCG(accel_directives).load_comments);
     693           0 :         add_assoc_bool(directives,   "opcache.fast_shutdown",          ZCG(accel_directives).fast_shutdown);
     694           0 :         add_assoc_bool(directives,   "opcache.enable_file_override",   ZCG(accel_directives).file_override_enabled);
     695           0 :         add_assoc_long(directives,       "opcache.optimization_level",     ZCG(accel_directives).optimization_level);
     696             : 
     697           0 :         add_assoc_zval(return_value, "directives", directives);
     698             : 
     699             :         /*version */
     700           0 :         MAKE_STD_ZVAL(version);
     701           0 :         array_init(version);
     702           0 :         add_assoc_string(version, "version", ACCELERATOR_VERSION, 1);
     703           0 :         add_assoc_string(version, "opcache_product_name", ACCELERATOR_PRODUCT_NAME, 1);
     704           0 :         add_assoc_zval(return_value, "version", version);
     705             : 
     706             :         /* blacklist */
     707           0 :         MAKE_STD_ZVAL(blacklist);
     708           0 :         array_init(blacklist);
     709           0 :         zend_accel_blacklist_apply(&accel_blacklist, (apply_func_arg_t) add_blacklist_path, blacklist TSRMLS_CC);
     710           0 :         add_assoc_zval(return_value, "blacklist", blacklist);
     711             : }
     712             : 
     713             : /* {{{ proto void accelerator_reset()
     714             :    Request that the contents of the opcode cache to be reset */
     715           0 : static ZEND_FUNCTION(opcache_reset)
     716             : {
     717             :         /* keep the compiler happy */
     718             :         (void)ht; (void)return_value_ptr; (void)this_ptr; (void)return_value_used;
     719             : 
     720             : #if ZEND_EXTENSION_API_NO >= PHP_5_3_X_API_NO
     721           0 :         if (zend_parse_parameters_none() == FAILURE) {
     722           0 :                 RETURN_FALSE;
     723             :         }
     724             : #endif
     725             : 
     726           0 :         if (!validate_api_restriction(TSRMLS_C)) {
     727           0 :                 RETURN_FALSE;
     728             :         }
     729             : 
     730           0 :         if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled)) {
     731           0 :                 RETURN_FALSE;
     732             :         }
     733             : 
     734           0 :         zend_accel_schedule_restart(ACCEL_RESTART_USER TSRMLS_CC);
     735           0 :         RETURN_TRUE;
     736             : }
     737             : 
     738             : /* {{{ proto void opcache_invalidate(string $script [, bool $force = false])
     739             :    Invalidates cached script (in necessary or forced) */
     740           0 : static ZEND_FUNCTION(opcache_invalidate)
     741             : {
     742             :         char *script_name;
     743             :         int script_name_len;
     744           0 :         zend_bool force = 0;
     745             : 
     746           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &script_name, &script_name_len, &force) == FAILURE) {
     747           0 :                 return;
     748             :         }
     749             : 
     750           0 :         if (!validate_api_restriction(TSRMLS_C)) {
     751           0 :                 RETURN_FALSE;
     752             :         }
     753             : 
     754           0 :         if (zend_accel_invalidate(script_name, script_name_len, force TSRMLS_CC) == SUCCESS) {
     755           0 :                 RETURN_TRUE;
     756             :         } else {
     757           0 :                 RETURN_FALSE;
     758             :         }
     759             : }
     760             : 
     761           0 : static ZEND_FUNCTION(opcache_compile_file)
     762             : {
     763             :         char *script_name;
     764             :         int script_name_len;
     765             :         zend_file_handle handle;
     766           0 :         zend_op_array *op_array = NULL;
     767           0 :         zend_execute_data *orig_execute_data = NULL;
     768             : 
     769           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &script_name, &script_name_len) == FAILURE) {
     770           0 :                 return;
     771             :         }
     772             : 
     773           0 :         if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled)) {
     774           0 :                 zend_error(E_NOTICE, ACCELERATOR_PRODUCT_NAME " seems to be disabled, can't compile file");
     775           0 :                 RETURN_FALSE;
     776             :         }
     777             : 
     778           0 :         handle.filename = script_name;
     779           0 :         handle.free_filename = 0;
     780           0 :         handle.opened_path = NULL;
     781           0 :         handle.type = ZEND_HANDLE_FILENAME;
     782             : 
     783           0 :         orig_execute_data = EG(current_execute_data);
     784             : 
     785           0 :         zend_try {
     786           0 :                 op_array = persistent_compile_file(&handle, ZEND_INCLUDE TSRMLS_CC);
     787           0 :         } zend_catch {
     788           0 :                 EG(current_execute_data) = orig_execute_data;
     789           0 :                 zend_error(E_WARNING, ACCELERATOR_PRODUCT_NAME " could not compile file %s", handle.filename);
     790           0 :         } zend_end_try();
     791             : 
     792           0 :         if(op_array != NULL) {
     793           0 :                 destroy_op_array(op_array TSRMLS_CC);
     794           0 :                 efree(op_array);
     795           0 :                 RETVAL_TRUE;
     796             :         } else {
     797           0 :                 RETVAL_FALSE;
     798             :         }
     799           0 :         zend_destroy_file_handle(&handle TSRMLS_CC);
     800             : }
     801             : 
     802             : /* {{{ proto bool opcache_is_script_cached(string $script)
     803             :    Return true if the script is cached in OPCache, false if it is not cached or if OPCache is not running. */
     804           0 : static ZEND_FUNCTION(opcache_is_script_cached)
     805             : {
     806             :         char *script_name;
     807             :         int script_name_len;
     808             : 
     809           0 :         if (!validate_api_restriction(TSRMLS_C)) {
     810           0 :                 RETURN_FALSE;
     811             :         }
     812             : 
     813           0 :         if (!ZCG(enabled) || !accel_startup_ok || !ZCSG(accelerator_enabled)) {
     814           0 :                 RETURN_FALSE;
     815             :         }
     816             : 
     817           0 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &script_name, &script_name_len) == FAILURE) {
     818           0 :                 return;
     819             :         }
     820             : 
     821           0 :         RETURN_BOOL(filename_is_in_cache(script_name, script_name_len TSRMLS_CC));
     822             : }

Generated by: LCOV version 1.10

Generated at Tue, 22 Jul 2014 01:33:14 +0000 (6 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.