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 6a56800
Browse filesBrowse the repository at this point in the historyBrowse files
|`OnMessage`|`OnMessageInterface`| Workerman `onMessage` callback: builds the PSR-7 request, calls the PSR-15 handler and emits the response. |
123
+
|`PsrRequestFactory`|`PsrRequestFactoryInterface`| Converts a workerman request into a PSR-7 server request via the given PSR-17 factories. |
124
+
|`WorkermanResponseEmitter`|`WorkermanResponseEmitterInterface`| Converts a PSR-7 response into a workerman response and sends it over the connection. |
125
+
126
+
`PsrRequestFactory` maps the following data:
127
+
128
+
* method, URI and all headers
129
+
* cookies, query params and the parsed body (form data)
130
+
* uploaded files, including nested ones (as `UploadedFileInterface` instances)
131
+
* the raw body, written to the request body stream
132
+
* server params `REMOTE_ADDR` and `REMOTE_PORT` from the TCP connection
133
+
134
+
### Long-running process caveats
135
+
136
+
Workerman keeps the PHP process alive between requests, which differs from PHP-FPM:
137
+
138
+
* Superglobals like `$_GET`, `$_POST`, `$_SERVER` or `$_COOKIE` are not populated. Read everything from the
139
+
PSR-7 request instead.
140
+
* Anything you keep in static properties or in long-lived services persists across requests. Avoid request
141
+
specific state in shared objects, or reset it per request.
142
+
* Only `REMOTE_ADDR` and `REMOTE_PORT` are available as server params. If you run behind a reverse proxy,
143
+
use a middleware such as [chubbyphp/chubbyphp-trusted-proxy][16] to resolve the client IP from headers.
144
+
145
+
### With Blackfire
146
+
147
+
`BlackfireOnMessageAdapter` wraps an `OnMessageInterface` and profiles a request whenever the
148
+
`X-Blackfire-Query` header is present, for example when triggered by the Blackfire browser extension or the
149
+
`blackfire curl` command. Requests without that header pass through untouched. The probe is always ended,
150
+
even if the wrapped handler throws.
151
+
152
+
Requires the `blackfire` extension and the [blackfire/php-sdk][17] package.
88
153
89
154
```php
90
155
<?php
@@ -94,20 +159,36 @@ declare(strict_types=1);
94
159
namespace App;
95
160
96
161
use Blackfire\Client;
162
+
use Blackfire\Profile\Configuration;
97
163
use Chubbyphp\WorkermanRequestHandler\Adapter\BlackfireOnMessageAdapter;
98
-
use Chubbyphp\WorkermanRequestHandler\OnMessage;
164
+
use Chubbyphp\WorkermanRequestHandler\OnMessageInterface;
165
+
use Psr\Log\LoggerInterface;
99
166
100
-
/** @var OnMessage $onMessage */
167
+
/** @var OnMessageInterface $onMessage */
101
168
$onMessage = ...;
102
169
103
-
if (extension_loaded('blackfire') {
104
-
$onMessage = new BlackfireOnMessageAdapter($onMessage, new Client());
170
+
/** @var LoggerInterface $logger */
171
+
$logger = ...;
172
+
173
+
if (extension_loaded('blackfire')) {
174
+
$onMessage = new BlackfireOnMessageAdapter(
175
+
$onMessage,
176
+
new Client(),
177
+
new Configuration(), // optional, defaults to new Configuration()
178
+
$logger // optional, defaults to a NullLogger; receives Blackfire client errors
179
+
);
105
180
}
106
181
107
182
$http->onMessage = $onMessage;
108
183
```
109
184
110
-
### with newrelic
185
+
### With New Relic
186
+
187
+
`NewRelicOnMessageAdapter` wraps an `OnMessageInterface` and starts a New Relic transaction for every request.
188
+
The transaction is always ended, even if the wrapped handler throws, so each request is reported separately
189
+
instead of as one endless transaction per worker process.
190
+
191
+
Requires the `newrelic` extension.
111
192
112
193
```php
113
194
<?php
@@ -117,18 +198,20 @@ declare(strict_types=1);
117
198
namespace App;
118
199
119
200
use Chubbyphp\WorkermanRequestHandler\Adapter\NewRelicOnMessageAdapter;
120
-
use Chubbyphp\WorkermanRequestHandler\OnMessage;
201
+
use Chubbyphp\WorkermanRequestHandler\OnMessageInterface;
121
202
122
-
/** @var OnMessage $onMessage */
203
+
/** @var OnMessageInterface $onMessage */
123
204
$onMessage = ...;
124
205
125
-
if (extension_loaded('newrelic') && false !== $name = ini_get('newrelic.appname')) {
126
-
$onMessage = new NewRelicOnMessageAdapter($onMessage, $name);
206
+
if (extension_loaded('newrelic') && false !== $appname = ini_get('newrelic.appname')) {
207
+
$onMessage = new NewRelicOnMessageAdapter($onMessage, $appname);
127
208
}
128
209
129
210
$http->onMessage = $onMessage;
130
211
```
131
212
213
+
Both adapters implement `OnMessageInterface`, so they can be combined by nesting them.
0 commit comments