Skip to content

Instantly share code, notes, and snippets.

@DarkGL
Forked from fedek6/opcache-preload.php
Created April 17, 2024 05:51
Show Gist options
  • Save DarkGL/40dda601f64382055d9e6ad3f4170b7b to your computer and use it in GitHub Desktop.
Save DarkGL/40dda601f64382055d9e6ad3f4170b7b to your computer and use it in GitHub Desktop.
Working WordPress opcache preloading config
<?php
/**
* WordPress opcache preloading.
* Requires PHP >= 7.4.
*
* @author Konrad Fedorczyk <[email protected]>
* @link https://stitcher.io/blog/preloading-in-php-74
*
* @version 1.0.0
*/
/**
* Uwaga! Adjust your path.
*/
define('APP_PATH', '/home/developer/htdocs/oko/');
$preload_patterns = [
// WP native files (priority).
'wp-load.php',
'wp-includes/http.php',
'wp-includes/class-http.php',
'wp-includes/general-template.php',
'wp-includes/link-template.php',
'wp-includes/class-wp-http-response.php',
'wp-includes/class-wp-http-requests-hooks.php',
'wp-includes/class-wp-http-proxy.php',
'wp-includes/class-wp-http-requests-response.php',
'wp-includes/class-wp-http-cookie.php',
'wp-includes/class-wp-query.php',
'wp-includes/class-wp-tax-query.php',
'wp-includes/class-wp-user.php',
'wp-includes/class-wp-post.php',
'wp-includes/class-wp-roles.php',
'wp-includes/class-wp-role.php',
'wp-includes/taxonomy.php',
'wp-includes/post.php',
'wp-includes/user.php',
'wp-includes/pluggable.php',
'wp-includes/rest-api.php',
'wp-includes/kses.php',
'wp-includes/capabilities.php',
'wp-includes/comment.php',
'wp-includes/query.php',
'wp-includes/l10n.php',
'wp-includes/shortcodes.php',
'wp-includes/theme.php',
'wp-includes/post-template.php',
'wp-includes/post-thumbnail-template.php',
'wp-includes/media.php',
'wp-includes/date.php',
'wp-includes/author-template.php',
// Rest WP files.
"wp-includes/**/*.php",
"wp-includes/**/**/*.php",
"wp-includes/**/**/**/*.php",
"wp-includes/**/**/**/**/*.php",
];
foreach ($preload_patterns as $pattern) {
$files = glob(APP_PATH . $pattern);
foreach ($files as $file) {
opcache_compile_file($file);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment