Skip to content

Commit 07b3204

Browse files
authored
Update embedding.md
1 parent 7b036f7 commit 07b3204

File tree

1 file changed

+30
-112
lines changed

1 file changed

+30
-112
lines changed

customization/embedding.md

+30-112
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ go get -u github.com/roadrunner-server/roadrunner/v2024/lib
1717

1818
{% endcode %}
1919

20-
{% code title="main.go" %}
21-
22-
```go
23-
func handleRequest(w http.ResponseWriter, request *http.Request) {
24-
// Find a way to pass that to RoadRunner so PHP handles the request
25-
}
26-
```
27-
28-
{% endcode %}
2920

3021
## Create an RR instance
3122

@@ -37,9 +28,12 @@ import (
3728
"github.com/roadrunner-server/roadrunner/v2024/lib"
3829
)
3930

40-
overrides := []string{} // List of configuration overrides
41-
plugins := lib.DefaultPluginsList() // List of RR plugins to enable
42-
rr, err := lib.NewRR(".rr.yaml", overrides, plugins)
31+
func main() {
32+
overrides := []string{} // List of configuration overrides
33+
plugins := lib.DefaultPluginsList() // List of RR plugins to enable
34+
rr, err := lib.NewRR(".rr.yaml", overrides, plugins)
35+
}
36+
4337
```
4438

4539
{% endcode %}
@@ -52,79 +46,35 @@ You can, however, choose only the plugins you want and add your own private plug
5246
{% code title="main.go" %}
5347

5448
```go
55-
overrides := []string{
56-
"http.address=127.0.0.1:4444", // example override to set the http address
57-
"http.pool.num_workers=4", // example override of how to set the number of php workers
58-
} // List of configuration overrides
59-
plugins := []interface{}{
60-
&informer.Plugin{},
61-
&resetter.Plugin{},
62-
// ...
63-
&httpPlugin.Plugin{},
64-
// ...
65-
&coolCompany.Plugin{},
66-
}
67-
rr, err := roadrunner.NewRR(".rr.yaml", overrides, plugins)
68-
```
69-
70-
{% endcode %}
71-
72-
## Passing requests to RoadRunner
73-
74-
Roadrunner can respond to HTTP requests, but also gRPC ones or many more. Because this is all done via plugins that each
75-
listen to different types of requests, ports, etc...
76-
77-
So when we talk about passing a request to roadrunner, we're actually talking about passing the request to roadrunner's
78-
HTTP plugin. To do this, we need to keep a handle on the http plugin.
79-
80-
{% code title="main.go" %}
49+
import (
50+
"github.com/roadrunner-server/roadrunner/v2024/lib"
51+
httpPlugin "github.com/roadrunner-server/http/v5"
52+
"github.com/roadrunner-server/resetter/v5"
53+
"github.com/roadrunner-server/informer/v5"
54+
"github.com/yourCompay/yourCusomPlugin" // compillation error here, used only as an example.
55+
)
8156

82-
```go
83-
overrides := []string{} // List of configuration overrides
84-
httpPlugin := &httpPlugin.Plugin{},
85-
plugins := []interface{}{
86-
&informer.Plugin{},
87-
&resetter.Plugin{},
88-
// ...
89-
httpPlugin,
90-
// ...
91-
&coolCompany.Plugin{},
57+
func main() {
58+
overrides := []string{
59+
"http.address=127.0.0.1:4444", // example override to set the http address
60+
"http.pool.num_workers=4", // example override of how to set the number of php workers
61+
} // List of configuration overrides
62+
63+
plugins := []interface{}{
64+
&informer.Plugin{},
65+
&resetter.Plugin{},
66+
// ...
67+
&httpPlugin.Plugin{},
68+
// ...
69+
&yourCustomPlugin.Plugin{},
70+
}
71+
plugins := lib.DefaultPluginsList() // List of RR plugins to enable
72+
rr, err := lib.NewRR(".rr.yaml", overrides, plugins)
9273
}
93-
rr, err := roadrunner.NewRR(".rr.yaml", overrides, plugins)
9474
```
9575

9676
{% endcode %}
9777

98-
The HTTP plugin is itself an `http.Handler` so it's now very easy to use it to let roadrunner and PHP handle the
99-
request:
100-
101-
{% code title="main.go" %}
102-
103-
```go
104-
overrides := []string{
105-
// override the http plugin's address value for the current run of the program
106-
"http.address=127.0.0.1:4444",
107-
} // List of configuration overrides
108-
httpPlugin := &httpPlugin.Plugin{},
109-
plugins := []interface{}{
110-
&informer.Plugin{},
111-
&resetter.Plugin{},
112-
// ...
113-
httpPlugin,
114-
// ...
115-
&coolCompany.Plugin{},
116-
}
117-
rr, err := roadrunner.NewRR(".rr.yaml", overrides, plugins)
118-
if err != nil {
119-
return err
120-
}
121-
122-
func handleRequest(w http.ResponseWriter, request *http.Request) {
123-
return httpPlugin.ServeHTTP(w, request)
124-
}
125-
```
126-
127-
{% endcode %}
12878

12979
## Starting & Stopping Embedded Roadrunner
13080

@@ -143,36 +93,4 @@ go func() {
14393

14494
`rr.Serve()` will block until it returns an error or `nil` if it was stopped gracefully.
14595

146-
To gracefully stop the server, we simply call `rr.Stop()`
147-
148-
## Roadrunner State
149-
150-
When you run roadrunner, it goes through multiple phases of initialization, running, stopping etc...
151-
Sometimes it is useful to know about those, be it for debugging, to know if you're ready to accept requests, or if you
152-
can gracefully shutdown the main program.
153-
154-
You can call `rr.CurrentState()` on your roadrunner instance to retrieve one of the following states:
155-
156-
{% code title="main.go" %}
157-
158-
```go
159-
package fsm
160-
// github.com/roadrunner-server/endure/pkg/fsm
161-
162-
type State uint32
163-
164-
const (
165-
Uninitialized State = iota
166-
Initializing
167-
Initialized
168-
Starting
169-
Started
170-
Stopping
171-
Stopped
172-
Error
173-
)
174-
```
175-
176-
{% endcode %}
177-
178-
Additionally, the actual status name can be obtained via `rr.CurrentState().String()`.
96+
To gracefully stop the server, simply call `rr.Stop()`

0 commit comments

Comments
 (0)