Compare commits

...

1 Commits

Author SHA1 Message Date
Côme Chilliet 41df2668f2 feat: Add preload.php script for opcache preloading
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
2025-04-29 10:19:09 +02:00
3 changed files with 58 additions and 2 deletions
+3
View File
@@ -368,6 +368,9 @@ class OC {
}
public static function initSession(): void {
if (defined('PHP_PRELOAD')) {
return;
}
$request = Server::get(IRequest::class);
// TODO: Temporary disabled again to solve issues with CalDAV/CardDAV clients like DAVx5 that use cookies
+2 -2
View File
@@ -202,7 +202,7 @@ class Config {
unset($CONFIG);
// Invalidate opcache (only if the timestamp changed)
if (function_exists('opcache_invalidate')) {
if (!defined('PHP_PRELOAD') && function_exists('opcache_invalidate')) {
@opcache_invalidate($file, false);
}
@@ -233,7 +233,7 @@ class Config {
fclose($filePointer);
}
if (!defined('PHPUNIT_RUN') && headers_sent()) {
if (!defined('PHP_PRELOAD') && !defined('PHPUNIT_RUN') && headers_sent()) {
// syntax issues in the config file like leading spaces causing PHP to send output
$errorMessage = sprintf('Config file has leading content, please remove everything before "<?php" in %s', basename($file));
if (!defined('OC_CONSOLE')) {
+53
View File
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
define('PHP_PRELOAD', 1);
$_SERVER['SCRIPT_FILENAME'] = __DIR__ . '/index.php';
$_SERVER['SCRIPT_NAME'] = '/index.php';
require_once __DIR__ . '/lib/base.php';
function scanFolder(string $folder): void {
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($folder),
RecursiveIteratorIterator::LEAVES_ONLY
);
// names to skip
$skip = [
'update.php',
'index.php',
'cron.php',
'console.php',
'command.php',
'routes.php',
'authpicker.php',
'grant.php',
'/templates',
'composer/',
'tests/',
];
// require all
foreach ($files as $file) {
// check skipping
foreach ($skip as $s) {
if (strpos($file->getPathname(), $s) !== false) {
continue 2;
}
}
if (substr($file->getFilename(), -4) === '.php') {
require_once $file;
}
}
}
scanFolder(__DIR__ . '/lib');
scanFolder(__DIR__ . '/core');
// scanFolder(__DIR__ . '/apps');