Skip to content

Commit 9cb872c

Browse files
committed
fix(worker): skip zlib guard in worker mode
- mark worker bootstrap with an explicit CI_WORKER_MODE constant - keep the zlib.output_compression guard active for normal web requests - add regression coverage for worker boot with zlib output compression enabled - document the bug fix in the 4.7.3 changelog Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent 6a1543a commit 9cb872c

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎app/Config/Events.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
Events::on('pre_system', static function (): void {
2727
if (ENVIRONMENT !== 'testing') {
28-
if (ini_get('zlib.output_compression')) {
28+
if (! defined('CI_WORKER_MODE') && ini_get('zlib.output_compression')) {
2929
throw FrameworkException::forEnabledZlibOutputCompression();
3030
}
3131

‎system/Boot.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public static function bootWeb(Paths $paths): int
8787
*/
8888
public static function bootWorker(Paths $paths): CodeIgniter
8989
{
90+
if (! defined('CI_WORKER_MODE')) {
91+
define('CI_WORKER_MODE', true);
92+
}
93+
9094
static::definePathConstants($paths);
9195
if (! defined('APP_NAMESPACE')) {
9296
static::loadConstants();

‎tests/system/Commands/Worker/WorkerCommandsTest.php‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,36 @@ public function testWorkerInstallCreatesValidPHPFile(): void
167167
$this->assertStringContainsString('DatabaseConfig::cleanupForWorkerMode', (string) $content);
168168
}
169169

170+
public function testWorkerModeDoesNotRejectZlibOutputCompression(): void
171+
{
172+
$code = sprintf(<<<'PHP'
173+
$_SERVER['CI_ENVIRONMENT'] = 'development';
174+
define('FCPATH', %s . 'public' . DIRECTORY_SEPARATOR);
175+
require FCPATH . '../app/Config/Paths.php';
176+
177+
$paths = new Config\Paths();
178+
require $paths->systemDirectory . '/Boot.php';
179+
180+
CodeIgniter\Boot::bootWorker($paths);
181+
CodeIgniter\Events\Events::trigger('pre_system');
182+
183+
while (ob_get_level() > 0) {
184+
ob_end_clean();
185+
}
186+
187+
echo 'ok';
188+
PHP, var_export(ROOTPATH, true));
189+
190+
exec(
191+
escapeshellarg(PHP_BINARY) . ' -d zlib.output_compression=1 -r ' . escapeshellarg($code) . ' 2>&1',
192+
$output,
193+
$exitCode,
194+
);
195+
196+
$this->assertSame(0, $exitCode, implode("\n", $output));
197+
$this->assertSame(['ok'], $output);
198+
}
199+
170200
public function testWorkerInstallCreatesValidCaddyfile(): void
171201
{
172202
command('worker:install');

‎user_guide_src/source/changelogs/v4.7.3.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Bugs Fixed
4747
- **Database:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false.
4848
- **Kint:** Fixed a bug where stale Content Security Policy nonces were reused in worker mode, causing browser CSP violations for Debug Toolbar assets.
4949
- **Language:** Fixed a bug where ``Language::getLine()`` returned the literal dot-notation key instead of the nested array value when the requested key resolved to an intermediate array three or more levels deep.
50+
- **Worker:** Fixed a bug where the app starter's ``zlib.output_compression`` guard could throw in FrankenPHP worker mode.
5051
- **Toolbar:** Fixed a bug where the Logs collector raised an undefined property error when using a third-party PSR-3 logger.
5152
- **Time:** Fixed a bug where ``Time::createFromTimestamp()`` could fail for microsecond timestamps when ``LC_NUMERIC`` used a comma decimal separator.
5253
- **Validation:** Fixed a bug where ``Validation::getValidated()`` dropped fields whose validated value was explicitly ``null``.

0 commit comments

Comments
 (0)