Exemplo n.º 1
0
 /**
  * Loads a JSON file from cache or from the JSON file directly.
  *
  * @param string $path Path to the JSON file to load.
  *
  * @return mixed
  */
 public function load($path)
 {
     $real = $this->normalize($path);
     if (!$this->useCache) {
         return $this->loadJsonFromFile($path, $real);
     }
     $cache = str_replace($this->stripPath, '', $real);
     $cache = str_replace(['\\', '/'], '_', $cache);
     $cache = "{$this->cacheDir}/{$cache}.php";
     if ($this->hasOpcacheCheck && opcache_is_script_cached($cache) || file_exists($cache)) {
         return require $cache;
     }
     $data = $this->loadJsonFromFile($path, $real);
     file_put_contents($cache, "<?php return " . var_export($data, true) . ';');
     return $data;
 }
Exemplo n.º 2
0
 public function compileScripts()
 {
     if (!extension_loaded('Zend OPcache')) {
         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 (!\opcache_is_script_cached($file)) {
             // questo ciclo dovrebbe farlo solo allo start del ws, dato che una volta che sono tutti cacheati, controlla lui
             // se ci sono modifiche da fare dopo i secondi opcache.revalidate_freq passati dalla memorizzazione alla request
             Logger::debug('Ho compilato lo script ' . $file . ' perchè non era compilato', RENDER_CORE_LOGNAME);
             opcache_compile_file($file);
         }
     }
 }
 function __construct($di)
 {
     global $lgs_application_dir, $opcache_installed, $nocache;
     $this->di = $di;
     $controllerNamespace = '';
     if (!empty($di->routing['module'])) {
         $controllerNamespace .= '\\Modules\\' . ucfirst(strtolower($di->routing['module']));
         if (!empty($di->routing['submodule'])) {
             $controllerNamespace .= '\\Submodules\\' . ucfirst(strtolower($di->routing['submodule']));
         }
         $this->viewPath = $lgs_application_dir . 'app' . $controllerNamespace . '/views/';
     } else {
         $this->viewPath = $lgs_application_dir . 'app/views/';
     }
     $controllerNamespace .= '\\Controllers';
     $controllerNamespaceName = ucfirst(strtolower($di->routing['controller']));
     $controllerNamespace .= '\\' . $controllerNamespaceName;
     $controllerNamespaceClassName = $controllerNamespace . 'Controller';
     if ($opcache_installed) {
         $layoutId = 1;
         // depends on a file main layout/template now done in a dummy way
         $macrosPath = __DIR__ . '/../app//views/partials/macros/global_scope_profiles/profile-' . $layoutId . '.php';
         if ($nocache) {
             require_once __DIR__ . '/../app//views/partials/macros/global_scope_profiles/profile-' . $layoutId . '.php';
         }
         if (!opcache_is_script_cached($macrosPath)) {
             opcache_compile_file($macrosPath);
         }
     }
     if (!isset($di->view)) {
         $di->view = new View($di);
     }
     if (!isset($di->flow)) {
         $di->flow = new Flow($di);
     }
     if (!isset($di->db)) {
         $di->db = new Db($di);
     }
     Model::$staticdi = $di;
     Model::$staticdb = $di->db;
     $controller = new $controllerNamespaceClassName($di);
     $actionFunctionName = $di->routing['action'] . 'Action';
     $this->templateRelativePath = $controllerNamespaceName . '/' . $di->routing['action'] . '.php';
     $controller->{$actionFunctionName}();
     $templatePath = $this->viewPath . $this->templateRelativePath;
     if (file_exists($templatePath)) {
         include str_replace('\\', '/', $templatePath);
     }
 }
Exemplo n.º 4
0
    echo "Generated in <strong onclick='__();'>" . core_GetExecutionTime() . "</strong>";
    if (function_exists('db_GetQueryCount')) {
        if ($FOOTER_DATA_POINT++ > 0) {
            echo ',';
        }
        echo ' using ' . db_GetQueryCount() . (db_GetQueryCount() == 1 ? ' query' : ' queries');
    }
    if (function_exists('cache_GetReads')) {
        if ($FOOTER_DATA_POINT++ > 0) {
            echo ',';
        }
        echo ' ' . cache_GetReads() . ' cache read(s), ' . cache_GetWrites() . ' cache write(s)';
    }
    if (function_exists('opcache_is_script_cached')) {
        // Technically, this is checking if "footer.html.php" isn't cached //
        if (!opcache_is_script_cached(__FILE__)) {
            if ($FOOTER_DATA_POINT++ > 0) {
                echo ',';
            }
            echo " with opcache disabled";
        }
    } else {
        if ($FOOTER_DATA_POINT++ > 0) {
            echo ',';
        }
        echo " without opcache";
    }
    echo " <span class='view-mode'></span>";
    echo isset($GLOBALS['HTML_SHOW_FOOTER']) ? ' -->' : '</div>';
}
?>
Exemplo n.º 5
0
if ($need_admin) {
    // TODO: Do authentication check
    //	if ( blah ) {
    //		$is_admin = true;
    //	}
}
// PHP //
if (!$show_specific) {
    $response['name'] = gethostname();
    $response['php_version'] = PHP_VERSION;
}
// OpCache //
if (!$show_specific) {
    if (function_exists('opcache_is_script_cached')) {
        // Technically, this is checking if this file is cached //
        $response['opcache_enabled'] = opcache_is_script_cached(__FILE__);
    }
}
// APCu //
if (defined('CMW_USING_APCU') && !$show_specific) {
    $response['apcu_api_version'] = phpversion('apcu');
    if (function_exists('apcu_cache_info')) {
        $response['apcu_uptime'] = time() - intval(apcu_cache_info(true)['start_time']);
    }
}
// Database //
if (defined('CMW_USING_DB') && $show_db) {
    $response['db_api_version'] = phpversion('mysqli');
    if ($is_admin) {
        require_once __DIR__ . "/../../db.php";
        $db_data = db_QueryFetchPair("show VARIABLES like \"%version%\"");
Exemplo n.º 6
0
 /**
  * Require a file
  *
  * @access private
  * @param string $path
  */
 private function require_file($path)
 {
     $path = realpath($path);
     if (file_exists($path)) {
         require_once $path;
         // Opcache compilation
         $opcache_enabled = ini_get('opcache.enable');
         $opcache_cli_enabled = ini_get('opcache.enable_cli');
         if (php_sapi_name() == 'cli' and $opcache_cli_enabled or php_sapi_name() != 'cli' and $opcache_enabled) {
             if (function_exists('opcache_is_script_cached') and function_exists('opcache_compile_file')) {
                 if (!opcache_is_script_cached($path)) {
                     opcache_compile_file($path);
                 }
             }
         }
         return true;
     } else {
         throw new \Exception('File not found');
     }
 }
Exemplo n.º 7
0
 function render_admin_manual_page()
 {
     if (isset($_POST['action']) && isset($_POST['_wpnonce']) && check_admin_referer('opcache_ctrl', '_wpnonce')) {
         switch ($_POST['action']) {
             case 'compile':
                 if (isset($_POST['file']) && file_exists($_POST['file']) && !is_dir($_POST['file'])) {
                     if (version_compare(PHP_VERSION, '5.5.11') < 0 or !opcache_is_script_cached($_POST['file'])) {
                         opcache_compile_file($_POST['file']);
                         printf('<div class="updated"><p>%s</p></div>', esc_html__('Compiled!', 'opcache'));
                     } else {
                         printf('<div class="error"><p>%s</p></div>', esc_html__('The script is already cached.', 'opcache'));
                     }
                 } else {
                     printf('<div class="error"><p>%s</p></div>', esc_html__('No such file or directory.', 'opcache'));
                 }
                 break;
             case 'invalidate':
                 if (isset($_POST['file']) && file_exists($_POST['file']) && !is_dir($_POST['file'])) {
                     if (version_compare(PHP_VERSION, '5.5.11') < 0 or opcache_is_script_cached($_POST['file'])) {
                         if (isset($_POST['force']) && $_POST['force'] == 'on') {
                             opcache_invalidate($_POST['file'], true);
                             printf('<div class="updated"><p>%s</p></div>', esc_html__('Force Invalidated!', 'opcache'));
                         } else {
                             opcache_invalidate($_POST['file']);
                             printf('<div class="updated"><p>%s</p></div>', esc_html__('Invalidated!', 'opcache'));
                         }
                     } else {
                         printf('<div class="error"><p>%s</p></div>', esc_html__('The script is not cached yet.', 'opcache'));
                     }
                 } else {
                     printf('<div class="error"><p>%s</p></div>', esc_html__('No such file or directory.', 'opcache'));
                 }
                 break;
         }
     }
     $this->load_view('admin-manual.php');
 }
Exemplo n.º 8
0
/** Emit a JSON document.
*
*	Typically this is the last command in your document, but it doesn't have to be.
*
*	@param Array $out Response to output
*	@param Boolean $allow_jsonp Should JSON-P Callbacks be allowed? (Default: true)
**/
function json_Emit($out, $allow_jsonp = true)
{
    $prefix = "";
    $suffix = "";
    // By default, PHP will make '/' slashes in to '\/'. These flags fix that //
    $out_format = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES;
    // If 'pretty' mode (i.e. readable) //
    if (isset($_GET['pretty'])) {
        $out_format |= JSON_PRETTY_PRINT;
    }
    // JSON-P //
    if (isset($_GET['callback'])) {
        if ($allow_jsonp) {
            $callback = $_GET['callback'];
            if (json_IsValidJSONPCallback($callback)) {
                $prefix = $callback . "(";
                $suffix = ");";
            } else {
                $out = json_NewErrorResponse(400, "Invalid JSON-P Callback");
            }
        } else {
            $out = json_NewErrorResponse(401, "JSON-P Unavailable");
        }
    }
    // Debug Info //
    if (defined('CMW_PHP_DEBUG') && isset($_GET['debug'])) {
        $out['debug'] = [];
        if (isset($GLOBALS['_CORE_SCRIPT_TIMER'])) {
            $out['debug']['execute_time'] = core_MicrotimeToString($GLOBALS['_CORE_SCRIPT_TIMER']);
        }
        if (function_exists('db_GetQueryCount')) {
            $out['debug']['db_queries'] = db_GetQueryCount();
        }
        if (function_exists('cache_GetReads')) {
            $out['debug']['cache_reads'] = cache_GetReads();
            $out['debug']['cache_writes'] = cache_GetWrites();
        }
        if (function_exists('opcache_is_script_cached')) {
            // Technically, this is checking if "json.php" isn't cached //
            if (!opcache_is_script_cached(__FILE__)) {
                $out['debug']['opcache'] = "disabled";
            }
        } else {
            $out['debug']['opcache'] = "unavailable";
        }
        if (isset($_SERVER['PATH_INFO'])) {
            $out['debug']['url'] = $_SERVER['PATH_INFO'];
        }
        if (getenv('REDIRECT_URL')) {
            $out['debug']['redirect_url'] = getenv('REDIRECT_URL');
        }
        if (getenv('REDIRECT_QUERY_STRING')) {
            $out['debug']['redirect_query'] = getenv('REDIRECT_QUERY_STRING');
        }
    }
    // Output the Page //
    header('Content-Type: application/json');
    header("Cache-Control: no-cache, no-store, must-revalidate");
    // HTTP 1.1.
    //header("Pragma: no-cache"); // HTTP 1.0.
    //header("Expires: 0"); // Proxies.
    echo $prefix, str_replace('</', '<\\/', json_encode($out, $out_format)), $suffix;
}
Exemplo n.º 9
0
function lgs_autoloader($class)
{
    global $nocache, $opcache_installed;
    $class = str_replace('\\', '/', $class);
    $classParts = explode('/', $class);
    if ($classParts[0] == 'Models') {
        $includepath = __DIR__ . '/../app/' . $class . '.php';
    } else {
        if ($classParts[0] == 'Controllers') {
            $includepath = __DIR__ . '/../app/' . $class . '.php';
        } else {
            $includepath = __DIR__ . '/../app/Controllers/' . $class . '.php';
        }
    }
    include $includepath;
    if ($opcache_installed) {
        // reset in other logically better place so not to do it twice if ($nocache) opcache_reset();
        if (!opcache_is_script_cached($includepath)) {
            echo '<br / >some not cached';
            opcache_compile_file($includepath);
        } else {
            echo '<br / >some cached';
        }
    }
}
Exemplo n.º 10
0
<?php

var_dump(opcache_is_script_cached(__FILE__));
var_dump(opcache_is_script_cached("nonexistent.php"));