summaryrefslogtreecommitdiff
path: root/docs/integration/migration.md
blob: 5228f38c0a017886799c0df7eab754093c308a6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Migration from v1.0 to v2.0
To migration integration from RoadRunner v1.* to v2.* follow the next steps.

## Update Configuration
Second version of RoadRunner use single worker factory for all of its plugins. This means that you must include a new section
into your config `server` which is responsible for the worker creation. Limit service no longer presented as separate entity 
but rather part of specific service configuration.

```yaml
rpc:
  listen: tcp://127.0.0.1:6001

server:
  command: "php tests/psr-worker-bench.php"

http:
  address: "0.0.0.0:8080"
  pool:
    num_workers: 4
```

> Read more in [config reference](/intro/config.md).

## No longer worry about echoing
RoadRunner 2.0 intercepts all output to the STDOUT, this means you can start using default var_dump and other echo function
without breaking the communication. Yay!

## Explicitly declare PSR-15 dependency
We no longer ship the default PSR implementation with RoadRunner, make sure to include one you like the most by yourself.
For example:

```bash
$ composer require nyholm/psr7
```

## Update Worker Code
RoadRunner simplifies worker creation, use static `create()` method to automatically configure your worker:

```php
<?php

use Spiral\RoadRunner;

include "vendor/autoload.php";

$worker = RoadRunner\Worker::create();
```

Pass the PSR-15 factories to your PSR Worker:

```php
<?php

use Spiral\RoadRunner;
use Nyholm\Psr7;

include "vendor/autoload.php";

$worker = RoadRunner\Worker::create();
$psrFactory = new Psr7\Factory\Psr17Factory();

$worker = new RoadRunner\Http\PSR7Worker($worker, $psrFactory, $psrFactory, $psrFactory);
```

RoadRunner 2 unifies all workers to use similar naming, change `acceptRequest` to `waitRequest`:

```php
while ($req = $worker->waitRequest()) {
    try {
        $rsp = new Psr7\Response();
        $rsp->getBody()->write('Hello world!');

        $worker->respond($rsp);
    } catch (\Throwable $e) {
        $worker->getWorker()->error((string)$e);
    }
}
```

## Update RPCs
To create RPC client use new Goridge API:

```php
$rpc = \Spiral\Goridge\RPC\RPC::create('tcp://127.0.0.1:6001');
```