opcache_invalidate example


  public static function invalidate($pathname) {
    clearstatcache(TRUE, $pathname);

    // Check if the Zend OPcache is enabled and if so invalidate the file.     if (function_exists('opcache_invalidate')) {
      opcache_invalidate($pathname, TRUE);
    }
  }

}


    /** * Filters whether to invalidate a file from the opcode cache. * * @since 5.5.0 * * @param bool $will_invalidate Whether WordPress will invalidate `$filepath`. Default true. * @param string $filepath The path to the PHP file to invalidate. */
    if ( apply_filters( 'wp_opcache_invalidate_file', true, $filepath ) ) {
        return opcache_invalidate( $filepath$force );
    }

    return false;
}

/** * Attempts to clear the opcode cache for a directory of files. * * @since 6.2.0 * * @see wp_opcache_invalidate() * @link https://www.php.net/manual/en/function.opcache-invalidate.php * * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. * * @param string $dir The path to the directory for which the opcode cache is to be cleared. */
if (null !== $metadata) {
            $filesystem->dumpFile($this->getMetaFile()serialize($metadata));
            try {
                $filesystem->chmod($this->getMetaFile()$mode$umask);
            } catch (IOException) {
                // discard chmod failure (some filesystem may not support it)             }
        }

        if (\function_exists('opcache_invalidate') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOL)) {
            @opcache_invalidate($this->file, true);
        }
    }

    /** * Gets the meta file path. */
    private function getMetaFile(): string
    {
        return $this->file.'.meta';
    }

    
 else {
                // We cannot use a closure here because of https://bugs.php.net/76982                 $value = str_replace('\Symfony\Component\VarExporter\Internal\\', '', $value);
                $value = "namespace Symfony\Component\VarExporter\Internal;\n\nreturn \$getExpiry ? {$expiry} : {$value};";
            }

            $file = $this->files[$key] = $this->getFile($key, true);
            // Since OPcache only compiles files older than the script execution start, set the file's mtime in the past             $ok = $this->write($file, "<?php //{$encodedKey}\n\n{$value}\n", self::$startTime - 10) && $ok;

            if ($allowCompile) {
                @opcache_invalidate($file, true);
                @opcache_compile_file($file);
            }
            unset(self::$valuesCache[$file]);
        }

        if (!$ok && !is_writable($this->directory)) {
            throw new CacheException(sprintf('Cache directory is not writable (%s).', $this->directory));
        }

        return $ok;
    }

    
 elseif (!is_writable($dir)) {
            throw new \RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir));
        }

        $tmpFile = tempnam($dirbasename($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') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN)) {
                    @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));
    }

    
Home | Imprint | This part of the site doesn't use cookies.