docs: rewrite JsonRpcBundle docs, add SDK docs, move them under docs/api
en/docs/api/json-rpc-bundle/functionality/events/async_output.md
new file +75
ā0
1
+
# rpc.async_output
2
+
3
+
::::::block class="floatinginfobox floatinginfobox--fit"
4
+
:::::columns border zebra
5
+
::::row
6
+
:::col width="40%"
7
+
**Event name**
8
+
:::
9
+
:::col
10
+
`rpc.async_output`
11
+
:::
12
+
::::
13
+
::::row
14
+
:::col width="40%"
15
+
**Constant**
16
+
:::
17
+
:::col
18
+
`RpcEvent::OUTPUT_ASYNC`
19
+
:::
20
+
::::
21
+
::::row
22
+
:::col width="40%"
23
+
**Class**
24
+
:::
25
+
:::col
26
+
`RpcAsyncOutputEvent`
27
+
:::
28
+
::::
29
+
::::row
30
+
:::col width="40%"
31
+
**Properties**
32
+
:::
33
+
:::col
34
+
`RpcRequest $rpcRequest`, `RpcBatchRequest $batchRequest`, `string $output`
35
+
:::
36
+
::::
37
+
:::::
38
+
::::::
39
+
40
+
Dispatched in the **parent** [batch](/docs/api/json-rpc-bundle/functionality/batch) process in process mode (`batch.process: true`) when the `ufo:rpc:process` child process has finished. `$output` is the raw process output (the response JSON).
41
+
42
+
**Not dispatched** in inline batch mode and for single requests.
43
+
44
+
## Built-in listeners
45
+
46
+
| Priority | Listener | What it does |
47
+
| --- | --- | --- |
48
+
| 10 | `AsyncServerEventListener::process` | Parses `$output` into a response (empty or invalid output ā error), adds it to the batch and **always stops propagation** |
49
+
50
+
## What can be changed
51
+
52
+
* A listener with a priority **above 10** can change `$event->output` before parsing.
53
+
* Listeners with a priority of 10 and below are not called.
54
+
* Do not stop propagation above 10: the item will get no response and will most likely disappear from the batch result.
55
+
56
+
## Usage examples
57
+
58
+
* diagnostics: logging the raw output of child processes to find the cause of "Asynchronous request does not respond";
59
+
* metrics of duration and response size of batch items.
60
+
61
+
```php
62
+
#[AsEventListener(RpcEvent::OUTPUT_ASYNC, priority: 100)]
63
+
final class BatchOutputLogger
64
+
{
65
+
public function __construct(private LoggerInterface $logger) {}
66
+
67
+
public function __invoke(RpcAsyncOutputEvent $event): void
68
+
{
69
+
$this->logger->debug('batch item output', [
70
+
'method' => $event->rpcRequest->getMethod(),
71
+
'bytes' => strlen($event->output),
72
+
]);
73
+
}
74
+
}
75
+
```