Valider 3e245833 rédigé par marcimat's avatar marcimat
Parcourir les fichiers

fix: Être plus smart avant de reset l’opcache

Après une analyse plus approfondie, l’opcache sur certains hébergeemnts,
avec les Phar, pose problème… il n’arrive alors pas à charger les fichiers internes.

Plusieurs contournements :
- désactiver opcache s’il est actif semble suffisant
-- mais on tente d’abord sans le désactiver (parce que après tout ça fonctionne presque partout)
-- on retente désactivé
-- en dernier recours on execute opcache_reset() (bon là c’est très mal, car ça détruit le cache de tout le fpm de l’hébergement)
- require plutôt que require_once évite certains cas particuliers

Ce ce que j’ai vu LWS (un PHP 8.0, apache) nécessite la désactivation de l’opcache
De même que Nginx (PHP 8.2 sur Mamp Pro en local)

Au moins on ne vide pas le cache opcache brutalement maintenant.
parent 712393b2
Chargement en cours
Chargement en cours
Chargement en cours
Chargement en cours
+34 −8
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
@@ -5,17 +5,42 @@ use Spip\Loader\Debug;
$debug = false;

try {
	// clear opcache before disabling it
	if (function_exists( 'opcache_get_status' ) && opcache_get_status()) { opcache_reset(); }
	@ini_set('opcache.enable', 0); // disable zend opcode caching.
	@ini_set('apc.enabled', 0); // disable apc opcode caching (for later versions of APC)
	@ini_set('xcache.cacher', 0); // disable xcache opcode caching

	Phar::mapPhar('spip_loader.phar');
	require_once 'phar://spip_loader.phar/vendor/autoload.php';

	try {
		require 'phar://spip_loader.phar/vendor/autoload.php';
	} catch (\Error $e) {
		// @note \Error is PHP7+… (quid de PHP 5.6 ?)
		if (!(
			function_exists('opcache_get_status')
			&& opcache_get_status()
			&& (opcache_get_status()['opcache_enabled'])
			&& false !== strpos($e->getMessage(), sprintf('Failed opening required \'%s\'', 'phar://spip_loader.phar/vendor/autoload.php'))
		)) {
			throw $e;
		}

		// some hosting failed re-opening inside phar files :/
		@ini_set('opcache.enable', 0);
		try {
			require 'phar://spip_loader.phar/vendor/autoload.php';
			Debug::add('Disable opcache', 'Script disable opcache to start the Loader');
		} catch (\Error $e) {
			if (!(
				function_exists('opcache_reset')
				&& false !== strpos($e->getMessage(), sprintf('Failed opening required \'%s\'', 'phar://spip_loader.phar/vendor/autoload.php'))
			)) {
				throw $e;
			}
			// brutality mode :/
			opcache_reset();
			require 'phar://spip_loader.phar/vendor/autoload.php';
			Debug::add('Reset opcache', 'Script reset opcache to start the Loader (really bad thing 😢)');
		}
	}

	if (!http_response_code()) {
		require_once 'phar://spip_loader.phar/bin/console.php';
		require 'phar://spip_loader.phar/bin/console.php';
		exit(0);
	}

@@ -65,6 +90,7 @@ try {
	});

} catch (\Exception $e) {
	// @note use \Throwable when PHP 7+
	if ($debug) { echo $e->getMessage(); } else { throw $e; };
} catch (\Error $e) {
	if ($debug) { echo $e->getMessage(); } else { throw $e; };