public function compileScripts() { if (!extension_loaded('apc')) { return; } $files = array(); foreach ($this->_refresh_rules as $rules) { $rules = (object) $rules; $files = array_merge($files, File::getFilesFromDirectory($rules->dir, $rules->extension, $rules->recursive)); } foreach ($files as $file) { if (!$this->isFileCached($file)) { if ($d = \apc_delete_file($file)) { Logger::debug('Elimino dalla cache lo script ' . $file . ' per ricompilarlo', RENDER_CORE_LOGNAME); } else { Logger::debug('Non sono riuscito ad eliminare ' . $file . ' ' . print_r($d, true)); } if ($d = \apc_compile_file($file)) { Logger::debug('Ho compilato lo script ' . $file, 'core'); } else { Logger::debug('Non sono riuscito a compilare ' . $file . ' ' . print_r($d, true), 'core'); } } } }
public function compile($filename, $atomic = true) { if (CACHE_STATUS) { apc_compile_file($filename, $atomic); } return false; }
/** * {@inheritdoc} */ public function write($key, $content) { $dir = dirname($key); if (!is_dir($dir)) { if (false === @mkdir($dir, 0777, true)) { clearstatcache(false, $dir); if (!is_dir($dir)) { throw new RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir)); } } } elseif (!is_writable($dir)) { throw new RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir)); } $tmpFile = tempnam($dir, basename($key)); if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) { @chmod($key, 0666 & ~umask()); if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) { // Compile cached file into bytecode cache if (function_exists('opcache_invalidate')) { opcache_invalidate($key, true); } elseif (function_exists('apc_compile_file')) { apc_compile_file($key); } } return; } throw new RuntimeException(sprintf('Failed to write cache file "%s".', $key)); }
/** * Formats the output and saved it to disc. * * @param string $identifier filename * @param $contents $contents language array to save * @return bool \File::update result */ public function save($identifier, $contents) { // store the current filename $file = $this->file; // save it $return = parent::save($identifier, $contents); // existing file? saved? and do we need to flush the opcode cache? if ($file == $this->file and $return and static::$flush_needed) { if ($this->file[0] !== '/' and (!isset($this->file[1]) or $this->file[1] !== ':')) { // locate the file if ($pos = strripos($identifier, '::')) { // get the namespace path if ($file = \Autoloader::namespace_path('\\' . ucfirst(substr($identifier, 0, $pos)))) { // strip the namespace from the filename $identifier = substr($identifier, $pos + 2); // strip the classes directory as we need the module root $file = substr($file, 0, -8) . 'lang' . DS . $identifier; } else { // invalid namespace requested return false; } } else { $file = \Finder::search('lang', $identifier); } } // make sure we have a fallback $file or $file = APPPATH . 'lang' . DS . $identifier; // flush the opcode caches that are active static::$uses_opcache and opcache_invalidate($file, true); static::$uses_apc and apc_compile_file($file); } return $return; }
public function compile($filename, $atomic = TRUE) { if (_cacheStatus) { apc_compile_file($filename, $atomic); } return FALSE; }
public function flush_file($filename) { if (file_exists($filename)) { } else { if (file_exists(ABSPATH . $filename)) { $filename = ABSPATH . DIRECTORY_SEPARATOR . $filename; } elseif (file_exists(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $filename)) { $filename = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $filename; } elseif (file_exists(WPINC . DIRECTORY_SEPARATOR . $filename)) { $filename = WPINC . DIRECTORY_SEPARATOR . $filename; } elseif (file_exists(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $filename)) { $filename = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $filename; } else { return false; } } if (function_exists('opcache_invalidate')) { return opcache_invalidate($filename, true); } else { if (function_exists('apc_compile_file')) { return apc_compile_file($filename); } } return false; }
/** * write apc-cache() * * @param $file * @param $content */ protected function writeCacheFile($file, $content) { parent::writeCacheFile($file, $content); // Compile cached-file into bytecode-cache if (function_exists('apc_compile_file') === true) { apc_compile_file($file); } }
/** * Runs the APC cache to pre-cache the php files * returns true if all files where cached */ public static function RunAPC() { if (function_exists('apc_compile_file')) { $file01 = @apc_compile_file(DUPLICATOR_PLUGIN_PATH . "duplicator.php"); return $file01; } else { return false; } }
/** * {@inheritdoc} */ public function write($key, $content) { $this->filesystem->put($key, $content); // Compile cached file into bytecode cache if (function_exists('opcache_invalidate')) { opcache_invalidate($key, true); } elseif (function_exists('apc_compile_file')) { apc_compile_file($key); } }
/** * Сохраняет каталог в двоичном кэше * * @param string $dir_name * @param bool $recursively * * @return bool */ public static function compile_dir($dir_name, $recursively = true) { $compiled = true; if ($recursively) { foreach (glob($dir_name . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR) as $dir) { $compiled = $compiled && self::compile_dir($dir, $recursively); } } foreach (glob($dir_name . DIRECTORY_SEPARATOR . '*.php') as $file) { $compiled = $compiled && apc_compile_file($file); } return $compiled; }
/** * Sets a new dynamic configuration * * @param array $config */ public static function save($config) { $content = "<" . "?php return "; $content .= var_export($config, true); $content .= "; ?" . ">"; $configFile = self::getConfigFilePath(); file_put_contents($configFile, $content); if (function_exists('opcache_invalidate')) { opcache_reset(); opcache_invalidate($configFile); } if (function_exists('apc_compile_file')) { apc_compile_file($configFile); } }
/** * Compile Files for APC * The function runs through each directory and * compiles each *.php file through apc_compile_file * @param string $dir start directory * @return void */ function compile_files($dir, $exts = array('*.php')) { $dirs = glob($dir . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR); if (is_array($dirs) && count($dirs) > 0) { while (list(, $v) = each($dirs)) { compile_files($v, $exts); } } foreach ($exts as $ext) { echo "\n\n" . 'Compiling ' . $ext . "\n"; $files = glob($dir . DIRECTORY_SEPARATOR . $ext); if (is_array($files) && count($files) > 0) { while (list(, $v) = each($files)) { echo 'Compiling ' . $v . "\n"; apc_compile_file($v); } } } }
function compile_files($dir) { $dirs = glob($dir . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR); $files = glob($dir . DIRECTORY_SEPARATOR . '*.php'); if (is_array($files) && count($files) > 0) { while (list(, $v) = each($files)) { if (apc_compile_file($v)) { $GLOBALS["COMPILED"] = $GLOBALS["COMPILED"] + 1; } } } $files = glob($dir . DIRECTORY_SEPARATOR . '*.inc'); if (is_array($files) && count($files) > 0) { while (list(, $v) = each($files)) { if (apc_compile_file($v)) { $GLOBALS["COMPILED"] = $GLOBALS["COMPILED"] + 1; } } } }
/** * Formats the output and saved it to disk. * * @param $contents $contents config array to save * @return bool \File::update result */ public function save($contents) { // store the current filename $file = $this->file; // save it $return = parent::save($contents); // existing file? saved? and do we need to flush the opcode cache? if ($file == $this->file and $return and static::$flush_needed) { if ($this->file[0] !== '/' and (!isset($this->file[1]) or $this->file[1] !== ':')) { // locate the file $file = \Finder::search('config', $this->file, $this->ext); } // make sure we have a fallback $file or $file = APPPATH . 'config' . DS . $this->file . $this->ext; // flush the opcode caches that are active static::$uses_opcache and opcache_invalidate($file, true); static::$uses_apc and apc_compile_file($file); } return $return; }
/** * Refreshes all active opcode caches for the specified file * * @param string $path Path to the file * @return boolean True on success, false on failure */ protected static function refreshOpcodeCache($path) { try { // Zend OPcache if (function_exists('opcache_invalidate')) { opcache_invalidate($path, true); } // Zend Optimizer+ if (function_exists('accelerator_reset')) { accelerator_reset(); } // APC if (function_exists('apc_compile_file') && !ini_get('apc.stat')) { apc_compile_file($path); } // eAccelerator if (function_exists('eaccelerator_purge') && !ini_get('eaccelerator.check_mtime')) { @eaccelerator_purge(); } // XCache if (function_exists('xcache_count') && !ini_get('xcache.stat')) { if (($count = xcache_count(XC_TYPE_PHP)) > 0) { for ($id = 0; $id < $count; $id++) { xcache_clear_cache(XC_TYPE_PHP, $id); } } } // WinCache if (function_exists('wincache_refresh_if_changed')) { wincache_refresh_if_changed(array($path)); } } catch (\Exception $exception) { return false; } return true; }
/** * Save the local configuration file */ public function save() { if ($this->strTop == '') { $this->strTop = '<?php'; } $strFile = trim($this->strTop) . "\n\n"; $strFile .= "### INSTALL SCRIPT START ###\n"; foreach ($this->arrData as $k => $v) { $strFile .= "{$k} = {$v}\n"; } $strFile .= "### INSTALL SCRIPT STOP ###\n"; $this->strBottom = trim($this->strBottom); if ($this->strBottom != '') { $strFile .= "\n" . $this->strBottom . "\n"; } $strTemp = md5(uniqid(mt_rand(), true)); // Write to a temp file first $objFile = fopen(TL_ROOT . '/system/tmp/' . $strTemp, 'wb'); fputs($objFile, $strFile); fclose($objFile); // Make sure the file has been written (see #4483) if (!filesize(TL_ROOT . '/system/tmp/' . $strTemp)) { \System::log('The local configuration file could not be written. Have your reached your quota limit?', __METHOD__, TL_ERROR); return; } // Then move the file to its final destination $this->Files->rename('system/tmp/' . $strTemp, 'system/config/localconfig.php'); // Reset the Zend OPcache if (function_exists('opcache_invalidate')) { opcache_invalidate(TL_ROOT . '/system/config/localconfig.php', true); } // Reset the Zend Optimizer+ cache (unfortunately no API to delete just a single file) if (function_exists('accelerator_reset')) { accelerator_reset(); } // Recompile the APC file (thanks to Trenker) if (function_exists('apc_compile_file') && !ini_get('apc.stat')) { apc_compile_file(TL_ROOT . '/system/config/localconfig.php'); } // Purge the eAccelerator cache (thanks to Trenker) if (function_exists('eaccelerator_purge') && !ini_get('eaccelerator.check_mtime')) { @eaccelerator_purge(); } // Purge the XCache cache (thanks to Trenker) if (function_exists('xcache_count') && !ini_get('xcache.stat')) { if (($count = xcache_count(XC_TYPE_PHP)) > 0) { for ($id = 0; $id < $count; $id++) { xcache_clear_cache(XC_TYPE_PHP, $id); } } } }
/** *缓存文件 */ public static function cache_file($file) { return apc_compile_file($file); }
/** * Load fresh compiled template by including the PHP file * HHVM requires a work around because of a PHP incompatibility * * @param \Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template */ private function loadCompiledTemplate(Smarty_Internal_Template $_smarty_tpl) { if (function_exists('opcache_invalidate')) { opcache_invalidate($this->filepath, true); } elseif (function_exists('apc_compile_file')) { apc_compile_file($this->filepath); } if (defined('HHVM_VERSION')) { eval("?>" . file_get_contents($this->filepath)); } else { include $this->filepath; } }
/** * Write the rendered template output to cache * * @param Smarty_Internal_Template $_template template object * @param string $content content to cache * * @return boolean success */ public function writeCachedContent(Smarty_Internal_Template $_template, $content) { if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) { if (function_exists('opcache_invalidate')) { opcache_invalidate($_template->cached->filepath, true); } elseif (function_exists('apc_compile_file')) { apc_compile_file($_template->cached->filepath); } $cached = $_template->cached; $cached->timestamp = $cached->exists = is_file($cached->filepath); if ($cached->exists) { $cached->timestamp = filemtime($cached->filepath); return true; } } return false; }
/** * @param string $path The PHP file to invalidate. */ protected function invalidateCache($path) { function_exists('opcache_invalidate') && opcache_invalidate($path, true); function_exists('apc_compile_file') && apc_compile_file($path); }
/** * DUPLICATOR_RUN_APC * Runs the APC cache to pre-cache the php files * returns true if all files where cached */ function duplicator_run_apc() { if (function_exists('apc_compile_file')) { $file01 = @apc_compile_file(DUPLICATOR_PLUGIN_PATH . "duplicator.php"); return $file01; } else { return false; } }
<?php apc_compile_file($argv[1]); echo apc_bin_dumpfile(array($argv[1]), null, $argv[2]); ?>
<?php error_reporting(E_ALL); ini_set("display_errors", 1); echo "<pre>"; $file = "apc-1.php"; echo apc_compile_file($file);
// Remove restoration.php $basepath = KSROOTDIR; $basepath = rtrim(str_replace('\\', '/', $basepath), '/'); if (!empty($basepath)) { $basepath .= '/'; } $postproc->unlink($basepath . 'restoration.php'); // Import a custom finalisation file $filename = dirname(__FILE__) . '/restore_finalisation.php'; if (file_exists($filename)) { // opcode cache busting before including the filename if (function_exists('opcache_invalidate')) { opcache_invalidate($filename); } if (function_exists('apc_compile_file')) { apc_compile_file($filename); } if (function_exists('wincache_refresh_if_changed')) { wincache_refresh_if_changed(array($filename)); } if (function_exists('xcache_asm')) { xcache_asm($filename); } include_once $filename; } // Run a custom finalisation script if (function_exists('finalizeRestore')) { finalizeRestore($root, $basepath); } break; default:
/** * Writes a new configuration file array * * @param type $config */ public static function setConfiguration($config = array()) { $configFile = Yii::app()->params['dynamicConfigFile']; $content = "<" . "?php return "; $content .= var_export($config, true); $content .= "; ?" . ">"; file_put_contents($configFile, $content); if (function_exists('opcache_invalidate')) { opcache_invalidate($configFile); } if (function_exists('apc_compile_file')) { apc_compile_file($configFile); } }
/** * Method to call the given template. * It looks first at the given modules templates and then at the core templates (uses _findTemplate). * Output is either buffered ($buffer = TRUE) and returned as a string, or send directly to browser. * * @param string $tpl Name of template to call, including file extension but excluding path. * @param string $moduleName The name of the module to search for the template (if empty, search core). * @param string $type The type of template to call: 'content' or 'layout'. * @param TRUE $ |FALSE $buffer If TRUE buffer output and return as string, else send to browser. * @return string |NULL If buffering returns output, else returns NULL. */ public function callTemplate($_magic__tpl, $_magic__type, $_magic__buffer = TRUE) { // objects that almost every template will use $this->setVarByRef('objConfig', $this->getObject('altconfig', 'config')); $this->setVarByRef('objSkin', $this->getObject('skin', 'skin')); $this->setVarByRef('objUser', $this->getObject('user', 'security')); $this->setVarByRef('objLanguage', $this->getObject('language', 'language')); $_magic__path = $this->objEngine->_findTemplate($_magic__tpl, $this->moduleName, $_magic__type); // extract the template vars // TODO: think some more about the extract flags to use extract($this->objEngine->_templateVars, EXTR_SKIP); extract($this->objEngine->_templateRefs, EXTR_SKIP | EXTR_REFS); if ($_magic__buffer) { ob_start(); } include $_magic__path; // was require if (extension_loaded('apc')) { $this->objConfig = $this->getObject('altconfig', 'config'); // apc_compile_file($this->objConfig); if ($this->objConfig->getenable_apc() == 'TRUE') { apc_compile_file($_magic__path); // apc_compile_file($_magic__tpl); } else { $this->objAPC = FALSE; } $this->cacheTTL = $this->objConfig->getcache_ttl(); } if ($_magic__buffer) { $_magic__pageContent = ob_get_contents(); ob_end_clean(); return $_magic__pageContent; } else { return NULL; // just to be explicit } }
function apc_add_directory($dir) { $result = array(); $cdir = scandir($dir); foreach ($cdir as $key => $value) { if (!in_array($value, array(".", ".."))) { if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) { $result[$value] = apc_add_directory($dir . DIRECTORY_SEPARATOR . $value); } else { if (strtolower(substr($value, -4)) == '.php') { $result[] = $dir . DIRECTORY_SEPARATOR . $value; apc_compile_file($dir . DIRECTORY_SEPARATOR . $value); } } } } return $result; }
/** * returns the compiled template file name * * @param Dwoo_Core $dwoo the dwoo instance that requests it * @param Dwoo_ICompiler $compiler the compiler that must be used * @return string */ public function getCompiledTemplate(Dwoo_Core $dwoo, Dwoo_ICompiler $compiler = null) { $compiledFile = $this->getCompiledFilename($dwoo); if ($this->compilationEnforced !== true && isset(self::$cache['compiled'][$this->compileId]) === true) { // already checked, return compiled file } elseif ($this->compilationEnforced !== true && $this->isValidCompiledFile($compiledFile)) { // template is compiled self::$cache['compiled'][$this->compileId] = true; } else { // compiles the template $this->compilationEnforced = false; if ($compiler === null) { $compiler = $dwoo->getDefaultCompilerFactory($this->getResourceName()); if ($compiler === null || $compiler === array('Dwoo_Compiler', 'compilerFactory')) { $compiler = Dwoo_Compiler::compilerFactory(); } else { $compiler = call_user_func($compiler); } } $this->compiler = $compiler; $compiler->setCustomPlugins($dwoo->getCustomPlugins()); $compiler->setSecurityPolicy($dwoo->getSecurityPolicy()); $this->makeDirectory(dirname($compiledFile), $dwoo->getCompileDir()); file_put_contents($compiledFile, $compiler->compile($dwoo, $this)); if ($this->chmod !== null) { chmod($compiledFile, $this->chmod); } if (extension_loaded('Zend OPcache')) { opcache_invalidate($compiledFile); } elseif (extension_loaded('apc')) { apc_compile_file($compiledFile); } self::$cache['compiled'][$this->compileId] = true; } return $compiledFile; }
/** * Stores a file in the bytecode cache, bypassing all filters * * @param string $file_name * @param bool|null $atomic * * @return bool */ public function compile_file($file_name = '', $atomic = false) : bool { if (empty($file_name)) { return false; } return apc_compile_file($file_name, $atomic); }
/** * Reload/compile a PHP file * @param $filename * @return bool */ function apc_reload_file($filename) { if (function_exists('apc_compile_file')) { if (!file_exists($filename)) { if (file_exists(ABSPATH . $filename)) { $filename = ABSPATH . DIRECTORY_SEPARATOR . $filename; } elseif (file_exists(WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $filename)) { $filename = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $filename; } elseif (file_exists(WPINC . DIRECTORY_SEPARATOR . $filename)) { $filename = WPINC . DIRECTORY_SEPARATOR . $filename; } elseif (file_exists(WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $filename)) { $filename = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $filename; } else { return false; } } return apc_compile_file($filename); } return false; }