Back to File class

Method canFlushFileCache

public static bool
canFlushFileCache
()
First we check if opcache is enabled Then we check if the opcache_invalidate function is available Lastly we check if the host has restricted which scripts can use opcache_invalidate using opcache.restrict_api.
Returns
  • bool TRUE if we can proceed to use opcache_invalidate to flush a file from the OPCache
Since
  • 4.0.1
Class: File
Project: Joomla

Method canFlushFileCache - Source code

/**
 * First we check if opcache is enabled
 * Then we check if the opcache_invalidate function is available
 * Lastly we check if the host has restricted which scripts can use opcache_invalidate using opcache.restrict_api.
 *
 * `$_SERVER['SCRIPT_FILENAME']` approximates the origin file's path, but `realpath()`
 * is necessary because `SCRIPT_FILENAME` can be a relative path when run from CLI.
 * If the host has this set, check whether the path in `opcache.restrict_api` matches
 * the beginning of the path of the origin file.
 *
 * @return boolean TRUE if we can proceed to use opcache_invalidate to flush a file from the OPCache
 *
 * @since 4.0.1
 */
public static function canFlushFileCache()
{
    if (isset(static::$canFlushFileCache)) {
        return static::$canFlushFileCache;
    }
    if (ini_get('opcache.enable') && function_exists('opcache_invalidate') && (!ini_get('opcache.restrict_api') || stripos(realpath($_SERVER['SCRIPT_FILENAME']), ini_get('opcache.restrict_api')) === 0)) {
        static::$canFlushFileCache = true;
    } else {
        static::$canFlushFileCache = false;
    }
    return static::$canFlushFileCache;
}