@@ -455,6 +455,27 @@ public static function hasSessionRelaxedExpiry(): bool {
455455 * Try to set some values to the required Nextcloud default
456456 */
457457 public static function setRequiredIniValues (): void {
458+ // Don't display errors and log them
459+ @ini_set ('display_errors ' , '0 ' );
460+ @ini_set ('log_errors ' , '1 ' );
461+
462+ // Try to configure php to enable big file uploads.
463+ // This doesn't work always depending on the webserver and php configuration.
464+ // Let's try to overwrite some defaults if they are smaller than 1 hour
465+
466+ if (intval (@ini_get ('max_execution_time ' ) ?: 0 ) < 3600 ) {
467+ @ini_set ('max_execution_time ' , strval (3600 ));
468+ }
469+
470+ if (intval (@ini_get ('max_input_time ' ) ?: 0 ) < 3600 ) {
471+ @ini_set ('max_input_time ' , strval (3600 ));
472+ }
473+
474+ // Try to set the maximum execution time to the largest time limit we have
475+ if (strpos (@ini_get ('disable_functions ' ), 'set_time_limit ' ) === false ) {
476+ @set_time_limit (max (intval (@ini_get ('max_execution_time ' )), intval (@ini_get ('max_input_time ' ))));
477+ }
478+
458479 @ini_set ('default_charset ' , 'UTF-8 ' );
459480 @ini_set ('gd.jpeg_ignore_warning ' , '1 ' );
460481 }
@@ -553,11 +574,21 @@ private static function performSameSiteCookieProtection(\OCP\IConfig $config): v
553574 }
554575
555576 public static function init (): void {
577+ // First handle PHP configuration and copy auth headers to the expected
578+ // $_SERVER variable before doing anything Server object related
579+ self ::setRequiredIniValues ();
580+ self ::handleAuthHeaders ();
581+
556582 // prevent any XML processing from loading external entities
557583 libxml_set_external_entity_loader (static function () {
558584 return null ;
559585 });
560586
587+ // Set default timezone before the Server object is booted
588+ if (!date_default_timezone_set ('UTC ' )) {
589+ throw new \RuntimeException ('Could not set timezone to UTC ' );
590+ }
591+
561592 // calculate the root directories
562593 OC ::$ SERVERROOT = str_replace ('\\' , '/ ' , substr (__DIR__ , 0 , -4 ));
563594
@@ -615,34 +646,6 @@ public static function init(): void {
615646 error_reporting (E_ALL );
616647 }
617648
618- // Don't display errors and log them
619- @ini_set ('display_errors ' , '0 ' );
620- @ini_set ('log_errors ' , '1 ' );
621-
622- if (!date_default_timezone_set ('UTC ' )) {
623- throw new \RuntimeException ('Could not set timezone to UTC ' );
624- }
625-
626-
627- //try to configure php to enable big file uploads.
628- //this doesn´t work always depending on the webserver and php configuration.
629- //Let´s try to overwrite some defaults if they are smaller than 1 hour
630-
631- if (intval (@ini_get ('max_execution_time ' ) ?: 0 ) < 3600 ) {
632- @ini_set ('max_execution_time ' , strval (3600 ));
633- }
634-
635- if (intval (@ini_get ('max_input_time ' ) ?: 0 ) < 3600 ) {
636- @ini_set ('max_input_time ' , strval (3600 ));
637- }
638-
639- //try to set the maximum execution time to the largest time limit we have
640- if (strpos (@ini_get ('disable_functions ' ), 'set_time_limit ' ) === false ) {
641- @set_time_limit (max (intval (@ini_get ('max_execution_time ' )), intval (@ini_get ('max_input_time ' ))));
642- }
643-
644- self ::setRequiredIniValues ();
645- self ::handleAuthHeaders ();
646649 $ systemConfig = Server::get (\OC \SystemConfig::class);
647650 self ::registerAutoloaderCache ($ systemConfig );
648651
0 commit comments