Skip to content

Commit 22895f0

Browse files
committed
wip
1 parent 76a2af0 commit 22895f0

File tree

7 files changed

+26
-46
lines changed

7 files changed

+26
-46
lines changed

app/Config/WorkerMode.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class WorkerMode
2121
* - `autoloader`: PSR-4 autoloading configuration
2222
* - `locator`: File locator
2323
* - `exceptions`: Exception handler
24-
* - `logger`: Logger instance
25-
* - `timer`: Performance timer
2624
* - `commands`: CLI commands registry
2725
* - `codeigniter`: Main application instance
2826
* - `superglobals`: Superglobals wrapper
@@ -35,8 +33,6 @@ class WorkerMode
3533
'autoloader',
3634
'locator',
3735
'exceptions',
38-
'logger',
39-
'timer',
4036
'commands',
4137
'codeigniter',
4238
'superglobals',

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,11 @@ $handler = static function () use ($app, $workerConfig) {
8787
->setFilesArray($_FILES)
8888
->setRequestArray($_REQUEST);
8989
90-
// Handle the request
91-
$app->run();
90+
try {
91+
$app->run();
92+
} catch (Throwable $e) {
93+
Services::exceptions()->exceptionHandler($e);
94+
}
9295

9396
if ($workerConfig->garbageCollection) {
9497
// Force garbage collection
@@ -117,20 +120,8 @@ while (frankenphp_handle_request($handler)) {
117120
// Reset services except persistent ones
118121
Services::resetForWorkerMode($workerConfig);
119122

120-
// Reset performance
121-
Events::cleanupForWorkerMode();
122-
123-
// Reset persistent services that accumulate state
124-
if (Services::has('timer')) {
125-
Services::timer()->reset();
126-
}
127-
128-
if (Services::has('logger')) {
129-
Services::logger()->reset();
130-
}
131-
132-
// Reset debug toolbar collectors (development only)
133-
if (CI_DEBUG && Services::has('toolbar')) {
123+
if (CI_DEBUG) {
124+
Events::cleanupForWorkerMode();
134125
Services::toolbar()->reset();
135126
}
136127
}

system/Debug/Timer.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,4 @@ public function record(string $name, callable $callable)
148148

149149
return $returnValue;
150150
}
151-
152-
/**
153-
* Reset all timers for worker mode.
154-
* Clears all timer data between requests.
155-
*/
156-
public function reset(): void
157-
{
158-
$this->timers = [];
159-
}
160151
}

system/Events/Events.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,13 @@ public static function getPerformanceLogs()
286286
}
287287

288288
/**
289-
* Cleanup performance log for worker mode.
289+
* Cleanup performance log and request-specific listeners for worker mode.
290290
*
291291
* Called at the END of each request to clean up state.
292292
*/
293293
public static function cleanupForWorkerMode(): void
294294
{
295295
static::$performanceLog = [];
296+
static::removeAllListeners('DBQuery');
296297
}
297298
}

system/Log/Logger.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,4 @@ public function determineFile(): array
376376

377377
return ['unknown', 'unknown'];
378378
}
379-
380-
/**
381-
* Reset log cache for worker mode.
382-
* Clears cached log entries between requests.
383-
*/
384-
public function reset(): void
385-
{
386-
if ($this->cacheLogs) {
387-
$this->logCache = [];
388-
}
389-
}
390379
}

user_guide_src/source/changelogs/v4.7.0.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Highlights
1515
**********
1616

1717
- Update minimal PHP requirement to ``8.2``.
18+
- Added experimental **FrankenPHP Worker Mode** support for improved performance.
1819

1920
********
2021
BREAKING
@@ -269,20 +270,26 @@ Libraries
269270
- **Image:** The ``ImageMagickHandler`` has been rewritten to rely solely on the PHP ``imagick`` extension.
270271
- **Image:** Added ``ImageMagickHandler::clearMetadata()`` method to remove image metadata for privacy protection.
271272
- **ResponseTrait:** Added ``paginate``` method to simplify paginated API responses. See :ref:`ResponseTrait::paginate() <api_response_trait_paginate>` for details.
273+
- **Session:** Added connection persistence for Redis and Memcached session handlers via ``PersistsConnection`` trait, improving performance in worker mode by reusing connections across requests.
272274
- **Time:** added methods ``Time::addCalendarMonths()`` and ``Time::subCalendarMonths()``
273275
- **Time:** Added ``Time::isPast()`` and ``Time::isFuture()`` convenience methods. See :ref:`isPast <time-comparing-two-times-isPast>` and :ref:`isFuture <time-comparing-two-times-isFuture>` for details.
274-
- **View:** Added the ability to override namespaced views (e.g., from modules/packages) by placing a matching file structure within the **app/Views/overrides** directory. See :ref:`Overriding Namespaced Views <views-overriding-namespaced-views>` for details.
275276
- **Toolbar:** Fixed an issue where the Debug Toolbar was incorrectly injected into responses generated by third-party libraries (e.g., Dompdf) that use native PHP headers instead of the framework's Response object.
277+
- **View:** Added the ability to override namespaced views (e.g., from modules/packages) by placing a matching file structure within the **app/Views/overrides** directory. See :ref:`Overriding Namespaced Views <views-overriding-namespaced-views>` for details.
278+
- **Worker Mode:** Added experimental FrankenPHP Worker Mode support, allowing CodeIgniter to handle multiple HTTP requests within the same PHP process for 2-3x performance improvements. See :doc:`Worker Mode </installation/worker_mode>` for details.
276279

277280
Commands
278281
========
279282

283+
- Added ``php spark worker:install`` command to generate FrankenPHP worker mode files (Caddyfile and worker entry point).
284+
- Added ``php spark worker:uninstall`` command to remove worker mode files.
285+
280286
Testing
281287
=======
282288

283289
Database
284290
========
285291

292+
- **BaseConnection:** Added ``ping()`` method to check if the database connection is still alive. Postgre uses native ``pg_ping()``, other drivers use ``SELECT 1``.
286293
- **Exception Logging:** All DB drivers now log database exceptions uniformly. Previously, each driver had its own log format.
287294

288295
Query Builder
@@ -324,10 +331,17 @@ Message Changes
324331
Changes
325332
*******
326333

334+
- **Boot:** Added ``Boot::bootWorker()`` method for one-time worker initialization.
335+
- **CodeIgniter:** Added ``CodeIgniter::resetForWorkerMode()`` method to reset request-specific state between worker requests.
336+
- **Config:** Added ``app/Config/WorkerMode.php`` for worker mode configuration (persistent services, garbage collection).
327337
- **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.
338+
- **DatabaseConfig:** Added ``Config::validateForWorkerMode()`` and ``Config::cleanupForWorkerMode()`` methods for database connection management in worker mode.
339+
- **Events:** Added ``Events::cleanupForWorkerMode()`` method.
328340
- **Format:** Added support for configuring ``json_encode()`` maximum depth via ``Config\Format::$jsonEncodeDepth``.
329341
- **Paths:** Added support for changing the location of the ``.env`` file via the ``Paths::$envDirectory`` property.
342+
- **Services:** Added ``Services::resetForWorkerMode()`` and ``Services::validateForWorkerMode()`` methods.
330343
- **Toolbar:** Added ``$disableOnHeaders`` property to **app/Config/Toolbar.php**.
344+
- **Toolbar:** Added ``Toolbar::reset()`` method to reset debug toolbar collectors.
331345

332346
************
333347
Deprecations

user_guide_src/source/installation/worker_mode.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ Getting Started
9191
Installation
9292
============
9393

94-
1. Install FrankenPHP following the `official documentation <https://frankenphp.dev/docs/>`_
94+
1. Install FrankenPHP following the `official documentation <https://frankenphp.dev/>`_
9595

96-
You can use a static binary or Docker. Here we will assume we use a static binary,
96+
You can use a static binary or Docker. Here, we will assume we use a static binary,
9797
which can be `downloaded directly <https://github.com/php/frankenphp/releases/>`_.
9898

9999
2. Install the Worker Mode template files using the spark command:
@@ -203,8 +203,6 @@ Service Purpose
203203
``autoloader`` PSR-4 autoloading configuration. Safe to persist as class maps don't change.
204204
``locator`` File locator for finding framework files. Caches file paths for performance.
205205
``exceptions`` Exception handler. Stateless, safe to reuse.
206-
``logger`` Logger instance. Maintains file handles for efficient logging.
207-
``timer`` Performance timer. Reset internally per request.
208206
``commands`` CLI commands registry. Only used during worker startup.
209207
``codeigniter`` Main application instance. Orchestrates the request/response cycle.
210208
``superglobals`` Superglobals wrapper. Properly isolated per request internally.

0 commit comments

Comments
 (0)