Skip to content

Commit 41f49bd

Browse files
apply code suggestions
Co-authored-by: John Paul E. Balandan, CPA <paulbalandan@gmail.com>
1 parent 5e6c5e4 commit 41f49bd

File tree

11 files changed

+34
-35
lines changed

11 files changed

+34
-35
lines changed

app/Config/WorkerMode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class WorkerMode
4141
];
4242

4343
/**
44-
* Garbage Collection
44+
* Force Garbage Collection
4545
*
4646
* Whether to force garbage collection after each request.
4747
* Helps prevent memory leaks at a small performance cost.
4848
*/
49-
public bool $garbageCollection = true;
49+
public bool $forceGarbageCollection = true;
5050
}

system/Cache/Handlers/PredisHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public function reconnect(): bool
224224
{
225225
try {
226226
$this->redis->disconnect();
227-
} catch (Exception $e) {
227+
} catch (Exception) {
228228
// Connection already dead, that's fine
229229
}
230230

system/Commands/Worker/Views/frankenphp-worker.php.tpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ $workerConfig = config('WorkerMode');
6969
*/
7070

7171
$handler = static function () use ($app, $workerConfig) {
72-
// Validate database connections before handling request
73-
DatabaseConfig::validateForWorkerMode();
72+
// Reconnect database connections before handling request
73+
DatabaseConfig::reconnectForWorkerMode();
7474
75-
// Validate cache connection before handling request
76-
Services::validateForWorkerMode();
75+
// Reconnect cache connection before handling request
76+
Services::reconnectCacheForWorkerMode();
7777
7878
// Reset request-specific state
7979
$app->resetForWorkerMode();
@@ -93,7 +93,7 @@ $handler = static function () use ($app, $workerConfig) {
9393
Services::exceptions()->exceptionHandler($e);
9494
}
9595

96-
if ($workerConfig->garbageCollection) {
96+
if ($workerConfig->forceGarbageCollection) {
9797
// Force garbage collection
9898
gc_collect_cycles();
9999
}

system/Config/BaseService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,13 @@ public static function reset(bool $initAutoloader = true)
375375
}
376376

377377
/**
378-
* Validate cache connections for worker mode at the start of a request.
378+
* Reconnect cache connection for worker mode at the start of a request.
379379
* Checks if cache connection is alive and reconnects if needed.
380380
*
381381
* This should be called at the beginning of each request in worker mode,
382382
* before the application runs.
383383
*/
384-
public static function validateForWorkerMode(): void
384+
public static function reconnectCacheForWorkerMode(): void
385385
{
386386
if (! isset(static::$instances['cache'])) {
387387
return;

system/Database/Config.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,12 @@ protected static function ensureFactory()
154154
}
155155

156156
/**
157-
* Validate database connections for worker mode at the start of a request.
158-
* Checks if connections are alive and reconnects if needed.
157+
* Reconnect database connections for worker mode at the start of a request.
159158
*
160159
* This should be called at the beginning of each request in worker mode,
161160
* before the application runs.
162161
*/
163-
public static function validateForWorkerMode(): void
162+
public static function reconnectForWorkerMode(): void
164163
{
165164
if (static::$instances === []) {
166165
return;

tests/system/Commands/WorkerCommandsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function testWorkerInstallCreatesValidPHPFile(): void
163163
$this->assertStringStartsWith('<?php', $content);
164164

165165
$this->assertStringContainsString('frankenphp_handle_request', (string) $content);
166-
$this->assertStringContainsString('DatabaseConfig::validateForWorkerMode', (string) $content);
166+
$this->assertStringContainsString('DatabaseConfig::reconnectForWorkerMode', (string) $content);
167167
$this->assertStringContainsString('DatabaseConfig::cleanupForWorkerMode', (string) $content);
168168
}
169169

tests/system/CommonSingleServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static function provideServiceNames(): iterable
9696
'has',
9797
'encrypter', // Encrypter needs a starter key
9898
'session', // Headers already sent
99-
'validateForWorkerMode',
99+
'reconnectCacheForWorkerMode',
100100
];
101101

102102
if ($services === []) {

tests/system/Config/ServicesTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,24 +540,24 @@ public function testResetForWorkerMode(): void
540540

541541
#[PreserveGlobalState(false)]
542542
#[RunInSeparateProcess]
543-
public function testValidateForWorkerMode(): void
543+
public function testReconnectCacheForWorkerMode(): void
544544
{
545545
Services::cache();
546546
$this->assertTrue(Services::has('cache'));
547547

548-
Services::validateForWorkerMode();
548+
Services::reconnectCacheForWorkerMode();
549549

550550
$this->assertTrue(Services::has('cache'));
551551
}
552552

553553
#[PreserveGlobalState(false)]
554554
#[RunInSeparateProcess]
555-
public function testValidateForWorkerModeWithNoCache(): void
555+
public function testReconnectCacheForWorkerModeWithNoCache(): void
556556
{
557557
Services::resetSingle('cache');
558558
$this->assertFalse(Services::has('cache'));
559559

560-
Services::validateForWorkerMode();
560+
Services::reconnectCacheForWorkerMode();
561561

562562
$this->assertFalse(Services::has('cache'));
563563
}

tests/system/Database/Live/WorkerModeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ public function testCleanupForWorkerMode(): void
4848
$this->assertNotFalse($this->getPrivateProperty($conn, 'connID'));
4949
}
5050

51-
public function testValidateForWorkerMode(): void
51+
public function testReconnectForWorkerMode(): void
5252
{
5353
$conn = Config::connect();
5454
$this->assertInstanceOf(BaseConnection::class, $conn);
5555
$this->assertNotFalse($this->getPrivateProperty($conn, 'connID'));
5656

57-
Config::validateForWorkerMode();
57+
Config::reconnectForWorkerMode();
5858

5959
$this->assertNotFalse($this->getPrivateProperty($conn, 'connID'));
6060
}

user_guide_src/source/changelogs/v4.7.0.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,11 @@ Changes
337337
- **CodeIgniter:** Added ``CodeIgniter::resetForWorkerMode()`` method to reset request-specific state between worker requests.
338338
- **Config:** Added ``app/Config/WorkerMode.php`` for worker mode configuration (persistent services, garbage collection).
339339
- **Cookie:** The ``CookieInterface::EXPIRES_FORMAT`` has been changed to ``D, d M Y H:i:s T`` to follow the recommended format in RFC 7231.
340-
- **DatabaseConfig:** Added ``Config::validateForWorkerMode()`` and ``Config::cleanupForWorkerMode()`` methods for database connection management in worker mode.
340+
- **DatabaseConfig:** Added ``Config::reconnectForWorkerMode()`` and ``Config::cleanupForWorkerMode()`` methods for database connection management in worker mode.
341341
- **Events:** Added ``Events::cleanupForWorkerMode()`` method.
342342
- **Format:** Added support for configuring ``json_encode()`` maximum depth via ``Config\Format::$jsonEncodeDepth``.
343343
- **Paths:** Added support for changing the location of the ``.env`` file via the ``Paths::$envDirectory`` property.
344-
- **Services:** Added ``Services::resetForWorkerMode()`` and ``Services::validateForWorkerMode()`` methods.
344+
- **Services:** Added ``Services::resetForWorkerMode()`` and ``Services::reconnectCacheForWorkerMode()`` methods.
345345
- **Toolbar:** Added ``$disableOnHeaders`` property to **app/Config/Toolbar.php**.
346346
- **Toolbar:** Added ``Toolbar::reset()`` method to reset debug toolbar collectors.
347347

0 commit comments

Comments
 (0)