From cd67d0dfad9944c00485f2662499e4fb8490b875 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 18 Nov 2026 13:48:53 +0530 Subject: [PATCH 1/3] fix(cache): don't store page-cache responses that set a cookie The Redis page cache of --cache PHP sites decided what to store from the request only, so a response that started a PHP session was stored and served to the next visitors with the first visitor's session in the page. srcache_store_skip now also skips when the response has a Set-Cookie header; srcache evaluates it after the response headers. A migration applies the same change to the main.conf of existing PHP sites with the page cache, only where the srcache_store_skip line is still the one EasyEngine wrote; customised files are left alone with a warning. The old file is backed up, running sites get nginx -t and a reload (the file is put back if nginx -t fails), and disabled sites are only edited. --- ...set_cookie_responses_in_php_page_cache.php | 325 ++++++++++++++++++ templates/config/nginx/main.conf.mustache | 3 +- 2 files changed, 327 insertions(+), 1 deletion(-) create mode 100644 migrations/container/20261117120100_site-type-php_skip_set_cookie_responses_in_php_page_cache.php diff --git a/migrations/container/20261117120100_site-type-php_skip_set_cookie_responses_in_php_page_cache.php b/migrations/container/20261117120100_site-type-php_skip_set_cookie_responses_in_php_page_cache.php new file mode 100644 index 0000000..64af7eb --- /dev/null +++ b/migrations/container/20261117120100_site-type-php_skip_set_cookie_responses_in_php_page_cache.php @@ -0,0 +1,325 @@ +is_first_execution ) { + $this->skip_this_migration = true; + + return; + } + + $this->sites = array_filter( + Site::all() ?: [], + function ( $site ) { + return self::SITE_TYPE === $site->site_type && $site->cache_nginx_fullpage; + } + ); + if ( empty( $this->sites ) ) { + $this->skip_this_migration = true; + } + } + + /** + * @throws EE\ExitException + */ + public function up() { + + if ( $this->skip_this_migration ) { + EE::debug( 'Skipping page-cache set-cookie migration as it is not needed.' ); + + return; + } + + // Not EE_BACKUP_DIR//: `ee site backup` and `ee site restore` empty that dir. + $this->backup_root = EE_BACKUP_DIR . '/page-cache-set-cookie-' . self::SITE_TYPE . '-' . date( 'Ymd-His' ); + if ( file_exists( $this->backup_root ) ) { + $this->backup_root .= '-' . getmypid(); + } + + foreach ( $this->sites as $site ) { + // One broken site must not block the upgrade of the others. + try { + $this->migrate_site( $site ); + } catch ( \Throwable $e ) { + EE::warning( sprintf( 'Could not update the page cache config of %s: %s. %s', $site->site_url, rtrim( $e->getMessage(), '.' ), self::manual_fix( $site ) ) ); + } + } + + if ( ! empty( $this->changed ) ) { + EE::log( 'Responses that set a cookie are no longer stored in the page cache of ' . count( $this->changed ) . ' ' . self::SITE_TYPE . ' site(s). The previous main.conf files are in ' . $this->backup_root ); + } + } + + /** + * Restores the files changed by up() and reloads their running nginx. + */ + public function down() { + + foreach ( array_reverse( $this->changed ) as $change ) { + try { + $this->restore( $change ); + $id = self::get_nginx_container( $change['site'] ); + $test = self::test_nginx( $id ); + if ( null === $test ) { + self::reload_nginx( $change['site'], $id ); + } else { + EE::warning( sprintf( 'Restored the main.conf of %1$s, but nginx -t failed in its nginx container (%2$s), so it was not reloaded. Run: ee site reload %1$s --nginx', $change['site']->site_url, $test ) ); + } + } catch ( \Throwable $e ) { + EE::warning( sprintf( 'Could not restore the main.conf of %s from %s: %s', $change['site']->site_url, $change['backup'], $e->getMessage() ) ); + } + } + $this->changed = []; + } + + /** + * @param Site $site Site with the page cache. + * + * @throws \Exception + */ + private function migrate_site( $site ) { + + $file = $site->site_fs_path . '/config/nginx/conf.d/main.conf'; + if ( ! file_exists( $file ) && ! is_link( $file ) ) { + throw new \Exception( "$file is missing" ); + } + + if ( ! function_exists( '\EE\Site\Utils\put_container_file_contents' ) ) { + throw new \Exception( 'this site-command version cannot change main.conf safely' ); + } + + // The site's nginx container can swap anything in its config volume, so main.conf is read and rewritten in place through a checked handle. + $base = realpath( $site->site_fs_path . '/config/nginx' ); + if ( false === $base ) { + throw new \Exception( 'could not resolve config/nginx' ); + } + $dir = $base . '/conf.d'; + $content = \EE\Site\Utils\get_container_file_contents( $file, $dir, self::MAX_SIZE ); + + $new_content = self::replace_line( $content ); + if ( null === $new_content ) { + if ( preg_match( '/^[ \t]*' . preg_quote( self::NEW_LINE, '/' ) . '/m', $content ) ) { + EE::debug( "$site->site_url: main.conf already skips responses that set a cookie." ); + } else { + EE::warning( "Left the page cache config of $site->site_url as it is: its srcache_store_skip line isn't the one EasyEngine wrote. " . self::manual_fix( $site ) ); + } + + return; + } + + $backup = $this->backup_root . '/' . $site->site_url . '/main.conf'; + try { + $this->fs->mkdir( dirname( $backup ), 0700 ); + $this->fs->dumpFile( $backup, $content ); + } catch ( \Throwable $e ) { + $this->remove_backup( $backup ); + throw new \Exception( "could not back up main.conf ({$e->getMessage()})" ); + } + + try { + \EE\Site\Utils\put_container_file_contents( $file, $dir, $new_content, $content, self::MAX_SIZE ); + } catch ( \Exception $e ) { + // A failed write may have left main.conf partly written; any other failure left it as it was. + if ( 0 === strpos( $e->getMessage(), 'could not write' ) ) { + throw new \Exception( $e->getMessage() . "; the previous file is $backup" ); + } + $this->remove_backup( $backup ); + throw $e; + } + + $change = [ + 'site' => $site, + 'file' => $file, + 'dir' => $dir, + 'backup' => $backup, + 'content' => $new_content, + ]; + + $id = self::get_nginx_container( $site ); + $test = self::test_nginx( $id ); + if ( null !== $test ) { + try { + $this->restore( $change ); + } catch ( \Exception $e ) { + throw new \Exception( "nginx -t failed in its nginx container ($test), and putting main.conf back failed too ({$e->getMessage()}); the previous file is $backup" ); + } + EE::warning( "Left the page cache config of $site->site_url as it is: nginx -t failed in its nginx container ($test). Fix that first. " . self::manual_fix( $site ) ); + + return; + } + + $this->changed[] = $change; + EE::debug( "$site->site_url: main.conf no longer stores responses that set a cookie; the previous file is $backup." ); + self::reload_nginx( $site, $id ); + } + + /** + * Return main.conf content with EasyEngine's srcache_store_skip line replaced, or null when it isn't there exactly once. + * + * @param string $content main.conf content. + * + * @return string|null + */ + public static function replace_line( string $content ) { + + $pattern = '/^([ \t]*)' . preg_quote( self::OLD_LINE, '/' ) . '([ \t]*)(\r?)$/m'; + if ( 1 !== substr_count( $content, 'srcache_store_skip' ) || 1 !== preg_match( $pattern, $content, $matches ) ) { + return null; + } + + list( , $indent, $trailing, $cr ) = $matches; + + return preg_replace_callback( + $pattern, + function () use ( $indent, $trailing, $cr ) { + return $indent . self::COMMENT . $cr . "\n" . $indent . self::NEW_LINE . $trailing . $cr; + }, + $content + ); + } + + /** + * Put back the file of one change, only while it still holds what up() wrote. + * + * @param array $change Entry of $changed. + * + * @throws \Exception + */ + private function restore( array $change ) { + + $old = @file_get_contents( $change['backup'] ); + if ( false === $old ) { + throw new \Exception( 'could not read the backup' ); + } + \EE\Site\Utils\put_container_file_contents( $change['file'], $change['dir'], $old, $change['content'], self::MAX_SIZE ); + $this->remove_backup( $change['backup'] ); + } + + /** + * @param string $backup Saved main.conf; its site dir and the backup root go too once empty. + */ + private function remove_backup( string $backup ) { + + try { + $this->fs->remove( dirname( $backup ) ); + } catch ( \Throwable $e ) { + EE::debug( "Could not remove $backup: {$e->getMessage()}" ); + + return; + } + // rmdir() refuses it while it holds other sites' backups. + @rmdir( dirname( $backup, 2 ) ); + } + + /** + * @param Site $site Site. + * + * @return string + */ + private static function manual_fix( $site ) { + + return "To stop the page cache from storing responses that set a cookie, change the srcache_store_skip line in $site->site_fs_path/config/nginx/conf.d/main.conf to '" . self::NEW_LINE . "' and run: ee site reload $site->site_url --nginx"; + } + + /** + * @param Site $site Site. + * + * @return string|null ID of the site's running nginx container, '' when none runs (or the site is disabled), null when the lookup failed (already warned). + */ + private static function get_nginx_container( $site ) { + + if ( ! $site->site_enabled ) { + return ''; + } + + $cwd = getcwd(); + $result = @chdir( $site->site_fs_path ) ? EE::launch( \EE_DOCKER::docker_compose_with_custom() . ' ps -q nginx' ) : null; + if ( false !== $cwd ) { + chdir( $cwd ); + } + + if ( null === $result || 0 !== $result->return_code ) { + EE::warning( "Could not check the nginx container of $site->site_url, so it may still use its previous main.conf. Run: ee site reload $site->site_url --nginx" ); + + return null; + } + + return trim( $result->stdout ); + } + + /** + * Run nginx -t in the site's running nginx container; a stopped one reads the file when it starts. + * + * @param string|null $id From get_nginx_container(). + * + * @return string|null The error when nginx -t failed, else null. + */ + private static function test_nginx( $id ) { + + if ( null === $id || '' === $id ) { + return null; + } + + $result = EE::launch( 'docker exec ' . escapeshellarg( $id ) . ' nginx -t' ); + if ( 0 === $result->return_code ) { + return null; + } + $lines = preg_split( '/\R/', trim( $result->stderr . "\n" . $result->stdout ) ); + + return '' !== $lines[0] ? $lines[0] : 'exit code ' . $result->return_code; + } + + /** + * Graceful reload, as `ee site reload --nginx` does after nginx -t. + * + * @param Site $site Site. + * @param string|null $id From get_nginx_container(). + */ + private static function reload_nginx( $site, $id ) { + + if ( null === $id || '' === $id ) { + return; + } + + $result = EE::launch( 'docker exec ' . escapeshellarg( $id ) . ' nginx -s reload' ); + if ( 0 === $result->return_code ) { + EE::debug( "$site->site_url: reloaded nginx." ); + } else { + EE::warning( "Could not reload nginx of $site->site_url. Run: ee site reload $site->site_url --nginx" ); + } + } +} diff --git a/templates/config/nginx/main.conf.mustache b/templates/config/nginx/main.conf.mustache index f7ab29d..dede435 100644 --- a/templates/config/nginx/main.conf.mustache +++ b/templates/config/nginx/main.conf.mustache @@ -63,7 +63,8 @@ server { try_files $uri =404; srcache_fetch_skip $skip; - srcache_store_skip $skip; + # Evaluated after the response headers: a response that sets a cookie (e.g. a new session) is never stored. + srcache_store_skip $skip$upstream_http_set_cookie; srcache_response_cache_control off; From a5de417156f805eddf2ea56f7b45b9fe087b1101 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 18 Nov 2026 14:24:25 +0530 Subject: [PATCH 2/3] fix(php-ini): add the missing final newline to custom.ini of PHP sites PHP sites get their custom.ini from site-type-wp's template, which ended without a newline, so a line appended to it joined the sendmail_path line. The template is fixed in site-type-wp; this migration appends the missing line break to the custom.ini of existing PHP sites. Nothing else changes and PHP reads the file the same way, so php-fpm isn't reloaded. --- ...hp_add_final_newline_to_php_custom_ini.php | 145 ++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 migrations/container/20261117120300_site-type-php_add_final_newline_to_php_custom_ini.php diff --git a/migrations/container/20261117120300_site-type-php_add_final_newline_to_php_custom_ini.php b/migrations/container/20261117120300_site-type-php_add_final_newline_to_php_custom_ini.php new file mode 100644 index 0000000..5be6414 --- /dev/null +++ b/migrations/container/20261117120300_site-type-php_add_final_newline_to_php_custom_ini.php @@ -0,0 +1,145 @@ +is_first_execution ) { + $this->skip_this_migration = true; + + return; + } + + $this->sites = array_filter( + Site::all() ?: [], + function ( $site ) { + return self::SITE_TYPE === $site->site_type; + } + ); + if ( empty( $this->sites ) ) { + $this->skip_this_migration = true; + } + } + + /** + * @throws EE\ExitException + */ + public function up() { + + if ( $this->skip_this_migration ) { + EE::debug( 'Skipping custom.ini final-newline migration as it is not needed.' ); + + return; + } + + foreach ( $this->sites as $site ) { + // One broken site must not block the upgrade of the others. + try { + $this->migrate_site( $site ); + } catch ( \Throwable $e ) { + EE::warning( sprintf( 'Could not add the missing final newline to the custom.ini of %s: %s.', $site->site_url, rtrim( $e->getMessage(), '.' ) ) ); + } + } + } + + /** + * Removes the newline again from the files changed by up(), while they still hold what up() wrote. + */ + public function down() { + + foreach ( array_reverse( $this->changed ) as $change ) { + try { + \EE\Site\Utils\put_container_file_contents( $change['file'], $change['dir'], $change['old'], $change['new'], self::MAX_SIZE ); + } catch ( \Throwable $e ) { + EE::warning( sprintf( 'Could not remove the final newline added to the custom.ini of %s: %s.', $change['site']->site_url, rtrim( $e->getMessage(), '.' ) ) ); + } + } + $this->changed = []; + } + + /** + * @param Site $site Site. + * + * @throws \Exception + */ + private function migrate_site( $site ) { + + $file = $site->site_fs_path . '/config/php/php/conf.d/custom.ini'; + if ( ! file_exists( $file ) && ! is_link( $file ) ) { + EE::debug( "$site->site_url: no custom.ini at $file." ); + + return; + } + + if ( ! function_exists( '\EE\Site\Utils\put_container_file_contents' ) ) { + throw new \Exception( 'this site-command version cannot change custom.ini safely' ); + } + + // The site's php container can swap anything in its config volume, so custom.ini is read and rewritten in place through a checked handle. + $base = realpath( $site->site_fs_path . '/config/php' ); + if ( false === $base ) { + throw new \Exception( 'could not resolve config/php' ); + } + $dir = $base . '/php/conf.d'; + $content = \EE\Site\Utils\get_container_file_contents( $file, $dir, self::MAX_SIZE ); + + $new_content = self::add_newline( $content ); + if ( null === $new_content ) { + EE::debug( "$site->site_url: custom.ini is empty or already ends with a newline." ); + + return; + } + + // The write fails without changing the file, or puts the old content back itself. + \EE\Site\Utils\put_container_file_contents( $file, $dir, $new_content, $content, self::MAX_SIZE ); + + $this->changed[] = [ + 'site' => $site, + 'file' => $file, + 'dir' => $dir, + 'old' => $content, + 'new' => $new_content, + ]; + EE::debug( "$site->site_url: added the missing final newline to custom.ini." ); + } + + /** + * Return the content with a final line break in the file's own style, or null when it is blank or already ends with one. + * + * @param string $content custom.ini content. + * + * @return string|null + */ + public static function add_newline( string $content ) { + + if ( '' === trim( $content ) || "\n" === substr( $content, -1 ) || "\r" === substr( $content, -1 ) ) { + return null; + } + + $eol = false !== strpos( $content, "\r\n" ) ? "\r\n" : ( false === strpos( $content, "\n" ) && false !== strpos( $content, "\r" ) ? "\r" : "\n" ); + + return $content . $eol; + } +} From e417f9d5d4fcf3437b1df978dacb502e8dd211f8 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 18 Nov 2026 14:30:28 +0530 Subject: [PATCH 3/3] fix(cache): clear stale page-cache entries and report pending sites in the migrations Pages stored under the old rule stayed in Redis for up to 4 hours after the upgrade and were still served, some with another visitor's session id in the page. Once a site's nginx uses the new rule (reloaded, or not running), the page cache migration now deletes that site's page-cache keys in the Redis it uses: the global one, which also covers disabled and stopped sites, or the site's own. A site whose nginx could not be checked or reloaded keeps the change but is counted as pending in the summary, and its cache is left alone until the new rule is live. The manual-fix warning now says to add $upstream_http_set_cookie to the existing srcache_store_skip value instead of replacing the line, a failed write says main.conf may be partly written and names the backup to copy back first, and comment lines that mention srcache_store_skip no longer make the migration skip a site. Rollback in both migrations reads up to the size of the file they wrote, so a file that the change made larger than 1 MiB is restored too. --- ...set_cookie_responses_in_php_page_cache.php | 98 +++++++++++++++---- ...hp_add_final_newline_to_php_custom_ini.php | 3 +- 2 files changed, 82 insertions(+), 19 deletions(-) diff --git a/migrations/container/20261117120100_site-type-php_skip_set_cookie_responses_in_php_page_cache.php b/migrations/container/20261117120100_site-type-php_skip_set_cookie_responses_in_php_page_cache.php index 64af7eb..54c0a32 100644 --- a/migrations/container/20261117120100_site-type-php_skip_set_cookie_responses_in_php_page_cache.php +++ b/migrations/container/20261117120100_site-type-php_skip_set_cookie_responses_in_php_page_cache.php @@ -24,6 +24,9 @@ class SkipSetCookieResponsesInPhpPageCache extends Base { /** Same as in templates/config/nginx/main.conf.mustache, so a migrated file matches a newly generated one. */ const COMMENT = '# Evaluated after the response headers: a response that sets a cookie (e.g. a new session) is never stored.'; + /** Prefix of the site's page-cache keys in Redis, as `set $key` in main.conf.mustache builds them. */ + const CACHE_KEY = '%s:http'; + /** @var Site[] */ private $sites = []; @@ -33,6 +36,9 @@ class SkipSetCookieResponsesInPhpPageCache extends Base { /** @var string|null Where up() saves the previous main.conf of each site it changes. */ private $backup_root; + /** @var int Changed sites whose running nginx may still use the previous main.conf (not found or not reloaded). */ + private $pending = 0; + public function __construct() { parent::__construct(); @@ -80,7 +86,8 @@ public function up() { } if ( ! empty( $this->changed ) ) { - EE::log( 'Responses that set a cookie are no longer stored in the page cache of ' . count( $this->changed ) . ' ' . self::SITE_TYPE . ' site(s). The previous main.conf files are in ' . $this->backup_root ); + $pending = $this->pending ? "; {$this->pending} more once their nginx is reloaded" : ''; + EE::log( 'Responses that set a cookie are no longer stored in the page cache of ' . ( count( $this->changed ) - $this->pending ) . ' ' . self::SITE_TYPE . " site(s)$pending. The previous main.conf files are in " . $this->backup_root ); } } @@ -104,6 +111,7 @@ public function down() { } } $this->changed = []; + $this->pending = 0; } /** @@ -155,7 +163,7 @@ private function migrate_site( $site ) { } catch ( \Exception $e ) { // A failed write may have left main.conf partly written; any other failure left it as it was. if ( 0 === strpos( $e->getMessage(), 'could not write' ) ) { - throw new \Exception( $e->getMessage() . "; the previous file is $backup" ); + throw new \Exception( $e->getMessage() . ", so it may be partly written: first copy back the previous file $backup" ); } $this->remove_backup( $backup ); throw $e; @@ -184,7 +192,13 @@ private function migrate_site( $site ) { $this->changed[] = $change; EE::debug( "$site->site_url: main.conf no longer stores responses that set a cookie; the previous file is $backup." ); - self::reload_nginx( $site, $id ); + // Until its nginx loads the change it can store such responses again, so clearing the cache would not last. + if ( null === $id || ! self::reload_nginx( $site, $id ) ) { + $this->pending++; + + return; + } + self::clear_page_cache( $site ); } /** @@ -197,7 +211,8 @@ private function migrate_site( $site ) { public static function replace_line( string $content ) { $pattern = '/^([ \t]*)' . preg_quote( self::OLD_LINE, '/' ) . '([ \t]*)(\r?)$/m'; - if ( 1 !== substr_count( $content, 'srcache_store_skip' ) || 1 !== preg_match( $pattern, $content, $matches ) ) { + // Comment lines don't count; any other mention, even after a directive on the same line, does. + if ( 1 !== preg_match_all( '/^(?![ \t]*#)[^\r\n]*srcache_store_skip/m', $content ) || 1 !== preg_match( $pattern, $content, $matches ) ) { return null; } @@ -225,7 +240,8 @@ private function restore( array $change ) { if ( false === $old ) { throw new \Exception( 'could not read the backup' ); } - \EE\Site\Utils\put_container_file_contents( $change['file'], $change['dir'], $old, $change['content'], self::MAX_SIZE ); + // The file holds the change, which can be larger than MAX_SIZE. + \EE\Site\Utils\put_container_file_contents( $change['file'], $change['dir'], $old, $change['content'], strlen( $change['content'] ) ); $this->remove_backup( $change['backup'] ); } @@ -252,7 +268,35 @@ private function remove_backup( string $backup ) { */ private static function manual_fix( $site ) { - return "To stop the page cache from storing responses that set a cookie, change the srcache_store_skip line in $site->site_fs_path/config/nginx/conf.d/main.conf to '" . self::NEW_LINE . "' and run: ee site reload $site->site_url --nginx"; + return "To stop the page cache from storing responses that set a cookie, add \$upstream_http_set_cookie to the end of the srcache_store_skip value in $site->site_fs_path/config/nginx/conf.d/main.conf, keeping what is there (EasyEngine's line becomes '" . self::NEW_LINE . "'), and run: ee site reload $site->site_url --nginx"; + } + + /** + * Delete the site's page-cache entries: those stored before the change may hold a response that set a cookie, e.g. another visitor's session id. + * + * @param Site $site Site. + */ + private static function clear_page_cache( $site ) { + + $prefix = sprintf( self::CACHE_KEY, $site->site_url ); + if ( 'redis' !== $site->cache_host ) { + $cleared = \EE\Site\Utils\clean_site_cache( $prefix ); + } else { + // A local redis goes with the site's containers, so a disabled site starts with an empty one. + $id = self::get_container( $site, 'redis' ); + if ( '' === $id ) { + EE::debug( "$site->site_url: its redis isn't running, so there is no page cache to clear." ); + + return; + } + $cleared = null !== $id && 0 === EE::launch( 'docker exec ' . escapeshellarg( $id ) . ' redis-cli --eval purge_all_cache.lua 0 , ' . escapeshellarg( $prefix . '*' ) )->return_code; + } + + if ( $cleared ) { + EE::debug( "$site->site_url: cleared its page cache." ); + } else { + EE::warning( "Could not clear the page cache of $site->site_url. The pages it stored before this upgrade expire within 4 hours." ); + } } /** @@ -262,23 +306,33 @@ private static function manual_fix( $site ) { */ private static function get_nginx_container( $site ) { + $id = self::get_container( $site, 'nginx' ); + if ( null === $id ) { + EE::warning( "Could not check the nginx container of $site->site_url, so it may still use its previous main.conf. Run: ee site reload $site->site_url --nginx" ); + } + + return $id; + } + + /** + * @param Site $site Site. + * @param string $service Compose service. + * + * @return string|null ID of its running container, '' when none runs (or the site is disabled), null when the lookup failed. + */ + private static function get_container( $site, string $service ) { + if ( ! $site->site_enabled ) { return ''; } $cwd = getcwd(); - $result = @chdir( $site->site_fs_path ) ? EE::launch( \EE_DOCKER::docker_compose_with_custom() . ' ps -q nginx' ) : null; + $result = @chdir( $site->site_fs_path ) ? EE::launch( \EE_DOCKER::docker_compose_with_custom() . " ps -q $service" ) : null; if ( false !== $cwd ) { chdir( $cwd ); } - if ( null === $result || 0 !== $result->return_code ) { - EE::warning( "Could not check the nginx container of $site->site_url, so it may still use its previous main.conf. Run: ee site reload $site->site_url --nginx" ); - - return null; - } - - return trim( $result->stdout ); + return null === $result || 0 !== $result->return_code ? null : trim( $result->stdout ); } /** @@ -308,18 +362,26 @@ private static function test_nginx( $id ) { * * @param Site $site Site. * @param string|null $id From get_nginx_container(). + * + * @return bool Whether nginx uses the file now: reloaded, or not running. */ private static function reload_nginx( $site, $id ) { - if ( null === $id || '' === $id ) { - return; + if ( null === $id ) { + return false; + } + if ( '' === $id ) { + return true; } $result = EE::launch( 'docker exec ' . escapeshellarg( $id ) . ' nginx -s reload' ); if ( 0 === $result->return_code ) { EE::debug( "$site->site_url: reloaded nginx." ); - } else { - EE::warning( "Could not reload nginx of $site->site_url. Run: ee site reload $site->site_url --nginx" ); + + return true; } + EE::warning( "Could not reload nginx of $site->site_url. Run: ee site reload $site->site_url --nginx" ); + + return false; } } diff --git a/migrations/container/20261117120300_site-type-php_add_final_newline_to_php_custom_ini.php b/migrations/container/20261117120300_site-type-php_add_final_newline_to_php_custom_ini.php index 5be6414..f69f24d 100644 --- a/migrations/container/20261117120300_site-type-php_add_final_newline_to_php_custom_ini.php +++ b/migrations/container/20261117120300_site-type-php_add_final_newline_to_php_custom_ini.php @@ -71,7 +71,8 @@ public function down() { foreach ( array_reverse( $this->changed ) as $change ) { try { - \EE\Site\Utils\put_container_file_contents( $change['file'], $change['dir'], $change['old'], $change['new'], self::MAX_SIZE ); + // The file holds the change, which can be a byte larger than MAX_SIZE. + \EE\Site\Utils\put_container_file_contents( $change['file'], $change['dir'], $change['old'], $change['new'], strlen( $change['new'] ) ); } catch ( \Throwable $e ) { EE::warning( sprintf( 'Could not remove the final newline added to the custom.ini of %s: %s.', $change['site']->site_url, rtrim( $e->getMessage(), '.' ) ) ); }