@@ -487,6 +487,27 @@ public static function hasSessionRelaxedExpiry(): bool {
487487 * Try to set some values to the required Nextcloud default
488488 */
489489 public static function setRequiredIniValues (): void {
490+ // Don't display errors and log them
491+ @ini_set ('display_errors ' , '0 ' );
492+ @ini_set ('log_errors ' , '1 ' );
493+
494+ // Try to configure php to enable big file uploads.
495+ // This doesn't work always depending on the webserver and php configuration.
496+ // Let's try to overwrite some defaults if they are smaller than 1 hour
497+
498+ if (intval (@ini_get ('max_execution_time ' ) ?: 0 ) < 3600 ) {
499+ @ini_set ('max_execution_time ' , strval (3600 ));
500+ }
501+
502+ if (intval (@ini_get ('max_input_time ' ) ?: 0 ) < 3600 ) {
503+ @ini_set ('max_input_time ' , strval (3600 ));
504+ }
505+
506+ // Try to set the maximum execution time to the largest time limit we have
507+ if (strpos (@ini_get ('disable_functions ' ), 'set_time_limit ' ) === false ) {
508+ @set_time_limit (max (intval (@ini_get ('max_execution_time ' )), intval (@ini_get ('max_input_time ' ))));
509+ }
510+
490511 @ini_set ('default_charset ' , 'UTF-8 ' );
491512 @ini_set ('gd.jpeg_ignore_warning ' , '1 ' );
492513 }
@@ -580,11 +601,21 @@ private static function performSameSiteCookieProtection(\OCP\IConfig $config): v
580601 }
581602
582603 public static function init (): void {
604+ // First handle PHP configuration and copy auth headers to the expected
605+ // $_SERVER variable before doing anything Server object related
606+ self ::setRequiredIniValues ();
607+ self ::handleAuthHeaders ();
608+
583609 // prevent any XML processing from loading external entities
584610 libxml_set_external_entity_loader (static function () {
585611 return null ;
586612 });
587613
614+ // Set default timezone before the Server object is booted
615+ if (!date_default_timezone_set ('UTC ' )) {
616+ throw new \RuntimeException ('Could not set timezone to UTC ' );
617+ }
618+
588619 // calculate the root directories
589620 OC ::$ SERVERROOT = str_replace ("\\" , '/ ' , substr (__DIR__ , 0 , -4 ));
590621
@@ -637,34 +668,6 @@ public static function init(): void {
637668 error_reporting (E_ALL );
638669 }
639670
640- // Don't display errors and log them
641- @ini_set ('display_errors ' , '0 ' );
642- @ini_set ('log_errors ' , '1 ' );
643-
644- if (!date_default_timezone_set ('UTC ' )) {
645- throw new \RuntimeException ('Could not set timezone to UTC ' );
646- }
647-
648-
649- //try to configure php to enable big file uploads.
650- //this doesn´t work always depending on the webserver and php configuration.
651- //Let´s try to overwrite some defaults if they are smaller than 1 hour
652-
653- if (intval (@ini_get ('max_execution_time ' ) ?? 0 ) < 3600 ) {
654- @ini_set ('max_execution_time ' , strval (3600 ));
655- }
656-
657- if (intval (@ini_get ('max_input_time ' ) ?? 0 ) < 3600 ) {
658- @ini_set ('max_input_time ' , strval (3600 ));
659- }
660-
661- //try to set the maximum execution time to the largest time limit we have
662- if (strpos (@ini_get ('disable_functions ' ), 'set_time_limit ' ) === false ) {
663- @set_time_limit (max (intval (@ini_get ('max_execution_time ' )), intval (@ini_get ('max_input_time ' ))));
664- }
665-
666- self ::setRequiredIniValues ();
667- self ::handleAuthHeaders ();
668671 $ systemConfig = Server::get (\OC \SystemConfig::class);
669672 self ::registerAutoloaderCache ($ systemConfig );
670673
0 commit comments