MDL-40415 add explicit OPcache support

This commit is contained in:
Petr Škoda 2013-07-01 21:06:44 +02:00
parent f8e6e5bc30
commit c05a50992e
17 changed files with 136 additions and 0 deletions

View File

@ -36,6 +36,12 @@ if (isset($_SERVER['REMOTE_ADDR'])) {
exit(1);
}
// Force OPcache reset if used, we do not want any stale caches
// when preparing test environment.
if (function_exists('opcache_reset')) {
opcache_reset();
}
$help =
"Command line Moodle installer, creates config.php and initializes database.
Please note you must execute this script with the same uid as apache

View File

@ -36,6 +36,12 @@ if (isset($_SERVER['REMOTE_ADDR'])) {
exit(1);
}
// Force OPcache reset if used, we do not want any stale caches
// when preparing test environment.
if (function_exists('opcache_reset')) {
opcache_reset();
}
$help =
"Advanced command line Moodle database installer.
Please note you must execute this script with the same uid as apache.

View File

@ -29,6 +29,12 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// Force OPcache reset if used, we do not want any stale caches
// when detecting if upgrade necessary or when running upgrade.
if (function_exists('opcache_reset') and !isset($_SERVER['REMOTE_ADDR'])) {
opcache_reset();
}
define('CLI_SCRIPT', true);
define('CACHE_DISABLE_ALL', true);

View File

@ -52,6 +52,12 @@ if (empty($_GET['cache']) and empty($_POST['cache'])) {
// we redirect to self once we known no upgrades are necessary.
// Note: $_GET and $_POST are used here intentionally because our param cleaning is not loaded yet.
define('CACHE_DISABLE_ALL', true);
// Force OPcache reset if used, we do not want any stale caches
// when detecting if upgrade necessary or when running upgrade.
if (function_exists('opcache_reset')) {
opcache_reset();
}
}
require('../config.php');

View File

@ -85,10 +85,18 @@ if ($uninstall) {
if ($pluginman->is_plugin_folder_removable($pluginfo->component)) {
$continueurl = new moodle_url($PAGE->url, array('delete' => $pluginfo->component, 'sesskey' => sesskey(), 'confirm' => 1));
echo $output->plugin_uninstall_results_removable_page($pluginman, $pluginfo, $progress, $continueurl);
// Reset op code caches.
if (function_exists('opcache_reset')) {
opcache_reset();
}
exit();
} else {
echo $output->plugin_uninstall_results_page($pluginman, $pluginfo, $progress);
// Reset op code caches.
if (function_exists('opcache_reset')) {
opcache_reset();
}
exit();
}
}
@ -131,6 +139,10 @@ if ($delete and $confirmed) {
// So long, and thanks for all the bugs.
fulldelete($pluginfo->rootdir);
// Reset op code caches.
if (function_exists('opcache_reset')) {
opcache_reset();
}
redirect($PAGE->url);
}

View File

@ -26,6 +26,12 @@ if (isset($_SERVER['REMOTE_ADDR'])) {
die(); // No access from web!
}
// Force OPcache reset if used, we do not want any stale caches
// when preparing test environment.
if (function_exists('opcache_reset')) {
opcache_reset();
}
// Is not really necessary but adding it as is a CLI_SCRIPT.
define('CLI_SCRIPT', true);

View File

@ -26,6 +26,12 @@ if (isset($_SERVER['REMOTE_ADDR'])) {
die; // no access from web!
}
// Force OPcache reset if used, we do not want any stale caches
// when preparing test environment.
if (function_exists('opcache_reset')) {
opcache_reset();
}
require_once(__DIR__.'/../../../../lib/clilib.php');
require_once(__DIR__.'/../../../../lib/phpunit/bootstraplib.php');
require_once(__DIR__.'/../../../../lib/testing/lib.php');

2
cache/locallib.php vendored
View File

@ -108,6 +108,8 @@ class cache_config_writer extends cache_config {
fflush($handle);
fclose($handle);
$locking->unlock('configwrite', 'config');
// Tell PHP to recompile the script.
core_component::invalidate_opcode_php_cache($cachefile);
} else {
throw new cache_exception('ex_configcannotsave', 'cache', '', null, 'Unable to open the cache config file.');
}

View File

@ -142,6 +142,7 @@ class core_component {
@chmod($cachefile, $CFG->filepermissions);
}
@unlink($cachefile.'.tmp'); // Just in case anything fails (race condition).
self::invalidate_opcode_php_cache($cachefile);
}
}
@ -735,4 +736,21 @@ $cache = '.var_export($cache, true).';
}
return $return;
}
/**
* Invalidate opcode cache for given file, this is intended for
* php files that are stored in dataroot.
*
* Note: we need it here because this class must be self-contained.
*
* @param string $file
*/
public static function invalidate_opcode_php_cache($file) {
if (function_exists('opcache_invalidate')) {
if (!file_exists($file)) {
return;
}
opcache_invalidate($file, true);
}
}
}

View File

@ -7216,6 +7216,11 @@ class core_string_manager implements string_manager {
// and re-populate it again
fulldelete($this->menucache);
$this->get_list_of_translations(true);
// Lang packs use PHP files in dataroot, it is better to invalidate opcode caches.
if (function_exists('opcache_reset')) {
opcache_reset();
}
}
/**

View File

@ -31,6 +31,15 @@ error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', '1');
ini_set('log_errors', '1');
// Make sure OPcache does not strip comments, we need them in phpunit!
if (ini_get('opcache.enable') and strtolower(ini_get('opcache.enable')) !== 'off') {
if (!ini_get('opcache.save_comments') or strtolower(ini_get('opcache.save_comments')) === 'off') {
ini_set('opcache.enable', 0);
} else {
ini_set('opcache.load_comments', 1);
}
}
require_once(__DIR__.'/bootstraplib.php');
require_once(__DIR__.'/../testing/lib.php');
require_once(__DIR__.'/classes/autoloader.php');

View File

@ -33,6 +33,15 @@ define('NO_DEBUG_DISPLAY', true);
*/
define('NO_MOODLE_COOKIES', true);
// Make sure OPcache does not strip comments, we need them for Zend!
if (ini_get('opcache.enable') and strtolower(ini_get('opcache.enable')) !== 'off') {
if (!ini_get('opcache.save_comments') or strtolower(ini_get('opcache.save_comments')) === 'off') {
ini_set('opcache.enable', 0);
} else {
ini_set('opcache.load_comments', 1);
}
}
require('../../config.php');
require_once("$CFG->dirroot/webservice/amf/locallib.php");

View File

@ -33,6 +33,15 @@ define('NO_DEBUG_DISPLAY', true);
*/
define('NO_MOODLE_COOKIES', true);
// Make sure OPcache does not strip comments, we need them for Zend!
if (ini_get('opcache.enable') and strtolower(ini_get('opcache.enable')) !== 'off') {
if (!ini_get('opcache.save_comments') or strtolower(ini_get('opcache.save_comments')) === 'off') {
ini_set('opcache.enable', 0);
} else {
ini_set('opcache.load_comments', 1);
}
}
require('../../config.php');
require_once("$CFG->dirroot/webservice/amf/locallib.php");

View File

@ -33,6 +33,15 @@ define('NO_DEBUG_DISPLAY', true);
*/
define('NO_MOODLE_COOKIES', true);
// Make sure OPcache does not strip comments, we need them for Zend!
if (ini_get('opcache.enable') and strtolower(ini_get('opcache.enable')) !== 'off') {
if (!ini_get('opcache.save_comments') or strtolower(ini_get('opcache.save_comments')) === 'off') {
ini_set('opcache.enable', 0);
} else {
ini_set('opcache.load_comments', 1);
}
}
require('../../config.php');
require_once("$CFG->dirroot/webservice/soap/locallib.php");

View File

@ -33,6 +33,15 @@ define('NO_DEBUG_DISPLAY', true);
*/
define('NO_MOODLE_COOKIES', true);
// Make sure OPcache does not strip comments, we need them for Zend!
if (ini_get('opcache.enable') and strtolower(ini_get('opcache.enable')) !== 'off') {
if (!ini_get('opcache.save_comments') or strtolower(ini_get('opcache.save_comments')) === 'off') {
ini_set('opcache.enable', 0);
} else {
ini_set('opcache.load_comments', 1);
}
}
require('../../config.php');
require_once("$CFG->dirroot/webservice/soap/locallib.php");

View File

@ -33,6 +33,15 @@ define('NO_DEBUG_DISPLAY', true);
*/
define('NO_MOODLE_COOKIES', true);
// Make sure OPcache does not strip comments, we need them for Zend!
if (ini_get('opcache.enable') and strtolower(ini_get('opcache.enable')) !== 'off') {
if (!ini_get('opcache.save_comments') or strtolower(ini_get('opcache.save_comments')) === 'off') {
ini_set('opcache.enable', 0);
} else {
ini_set('opcache.load_comments', 1);
}
}
require('../../config.php');
require_once("$CFG->dirroot/webservice/xmlrpc/locallib.php");

View File

@ -33,6 +33,15 @@ define('NO_DEBUG_DISPLAY', true);
*/
define('NO_MOODLE_COOKIES', true);
// Make sure OPcache does not strip comments, we need them for Zend!
if (ini_get('opcache.enable') and strtolower(ini_get('opcache.enable')) !== 'off') {
if (!ini_get('opcache.save_comments') or strtolower(ini_get('opcache.save_comments')) === 'off') {
ini_set('opcache.enable', 0);
} else {
ini_set('opcache.load_comments', 1);
}
}
require('../../config.php');
require_once("$CFG->dirroot/webservice/xmlrpc/locallib.php");