You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 367870d
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/changelogs/v4.7.7.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,5 +50,6 @@ Release Date: Unreleased
50
50
-**Session:** Fixed a bug where `MemcachedHandler` did not reset lock state in `close()` or release an existing lock for a different session ID in `lockSession()`, causing subsequent reads and session ID regeneration on the same handler instance to fail.
51
51
-**Session:** Fixed a bug where `Session::start()` did not remove an invalid session cookie from `Request`'s cached cookie global if cookies had already been read from `Request`.
52
52
-**Worker Mode:** Fixed a bug where every request that ended with an uncaught exception, including a `404 Page Not Found` without a 404 override, called `exit()` in the exception handler. This ended the worker script, so FrankenPHP booted a new one, and the worker loop skipped its cleanup after the request. The exception handler now returns to the worker loop.
53
+
-**Worker Mode:** Fixed a bug where routes limited with the `hostname` or `subdomain` options were matched against the first request the worker served, so a host-restricted route became reachable from any host, and a route limited to another host stayed unreachable, until the worker restarted. The `routes` service is no longer persistent by default, so route definitions are loaded for each request. See [Worker Mode Routes Are Reloaded Per Request](../installation/upgrade_477.md#worker-mode-routes-are-reloaded-per-request) for migration instructions.
53
54
54
55
See the repo's [CHANGELOG.md](https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md) for a complete list of bugs fixed.
Copy file name to clipboardExpand all lines: docs/installation/upgrade_477.md
+37-1Lines changed: 37 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,41 @@ With the default configuration most applications are unaffected, because `/`, `\
18
18
19
19
## Breaking Enhancements
20
20
21
+
## Behavior Changes
22
+
23
+
### Worker Mode Routes Are Reloaded Per Request
24
+
25
+
`Config\WorkerMode::$persistentServices` no longer contains `routes`.
26
+
27
+
`RouteCollection` reads the request host while it loads the route definitions, and drops the routes limited with the `hostname` or `subdomain` options that do not match the current request. While the routes service was persistent, those decisions were made once, from the first request the worker served, and were kept for the lifetime of the process. A route limited to a hostname then became reachable from any `Host` after that first request, and a route that lost the first decision stayed unreachable until the worker restarted. The routes service is not persistent anymore, so the route definitions are loaded for each request and the host is evaluated on every request, as in traditional PHP.
28
+
29
+
A new installation gets the updated default. Existing installations have their own copy of **app/Config/WorkerMode.php** in the project space, so it is not changed on upgrade. If your application uses the `hostname` or `subdomain` route options in Worker Mode, remove `routes` from `$persistentServices`:
30
+
31
+
```php
32
+
<?php
33
+
34
+
namespace Config;
35
+
36
+
class WorkerMode
37
+
{
38
+
// ...
39
+
/**
40
+
* @var list<string>
41
+
*/
42
+
public array $persistentServices = [
43
+
'autoloader',
44
+
'locator',
45
+
'exceptions',
46
+
'commands',
47
+
'codeigniter',
48
+
'superglobals',
49
+
'cache',
50
+
];
51
+
}
52
+
```
53
+
54
+
See [Persistent Services](worker_mode.md#persistent-services) for details.
55
+
21
56
## Project Files
22
57
23
58
Some files in the **project space** (root, app, public, writable) received updates. Due to these files being outside of the **system** scope they will not be changed without your intervention.
@@ -31,7 +66,8 @@ The following files received significant changes (including deprecations or visu
31
66
32
67
#### Config
33
68
34
-
-@TODO
69
+
-**app/Config/WorkerMode.php**
70
+
-`Config\WorkerMode::$persistentServices` no longer contains `routes`. See [Worker Mode Routes Are Reloaded Per Request](#worker-mode-routes-are-reloaded-per-request).
- Reuses existing connections and cached resources
40
+
- Reloads the route definitions, so the routes limited with the `hostname` or `subdomain` options are matched against the current request
40
41
- Resets only request-specific state (superglobals, request/response objects)
41
42
- Processes request and sends response
42
43
- Cleans up request-specific data
@@ -118,7 +119,7 @@ Worker Mode typically provides **2-3x performance improvements** for database-dr
118
119
|----|----|
119
120
|**Simple endpoints**| Applications returning minimal JSON responses show modest improvements (10-30%), as there's little bootstrap overhead to eliminate. |
120
121
|**Database queries**| Endpoints performing database queries typically see **2-3x** improvements from connection reuse and reduced initialization overhead. |
121
-
|**Complex bootstrap**| Applications with many services, routes, or configuration see the largest gains, as this overhead is eliminated entirely. |
122
+
|**Complex bootstrap**| Applications with many services or configuration see the largest gains, as this overhead is eliminated entirely. |
122
123
123
124
### Worker Count Considerations
124
125
@@ -136,7 +137,7 @@ All worker mode configuration is managed through the **app/Config/WorkerMode.php
136
137
137
138
| Option | Type | Description |
138
139
|----|----|----|
139
-
|**$persistentServices**| array | Services that persist across requests and are not reset. Services not in this list are destroyed after each request to prevent state leakage. Default: `['autoloader', 'locator', 'exceptions', 'commands', 'codeigniter', 'superglobals', 'routes', 'cache']`|
140
+
|**$persistentServices**| array | Services that persist across requests and are not reset. Services not in this list are destroyed after each request to prevent state leakage. Default: `['autoloader', 'locator', 'exceptions', 'commands', 'codeigniter', 'superglobals', 'cache']`|
140
141
|**$resetEventListeners**| array | Event names whose listeners are removed between requests. Use this when you register event listeners inside other event callbacks rather than at the top level of **Config/Events.php**, which would cause them to accumulate across requests. Default: `[]`|
141
142
|**$forceGarbageCollection**| bool | Whether to force garbage collection after each request. `true` (default, recommended): Prevents memory leaks. `false`: Relies on PHP's automatic garbage collection. |
142
143
@@ -152,9 +153,11 @@ The `$persistentServices` array controls which services survive between requests
152
153
|`commands`| CLI commands registry. Only used during worker startup. |
153
154
|`codeigniter`| Main application instance. Orchestrates the request/response cycle. |
154
155
|`superglobals`| Superglobals wrapper. Properly isolated per request internally. |
155
-
|`routes`| Router configuration. Route definitions don't change between requests. |
The `routes` service is **not** persistent by default. `RouteCollection` reads the request host while it loads the route definitions, and drops the routes limited with the `hostname` or `subdomain` options that do not match the current request. A persistent route collection would keep the decision made for the first request the worker served, so the routes restricted to a hostname would be reachable from any host, or not reachable at all, until the worker restarted. The route definitions are therefore loaded again for each request. The cost is small compared with the bootstrap work Worker Mode already removes, and it keeps the route behavior identical to traditional PHP.
160
+
158
161
!!! warning "Warning"
159
162
Adding services to `$persistentServices` without understanding their state management can cause data leakage between requests. Only persist services that are truly stateless or manage their own request isolation.
0 commit comments