@@ -17,15 +17,6 @@ go get -u github.com/roadrunner-server/roadrunner/v2024/lib
17
17
18
18
{% endcode %}
19
19
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 %}
29
20
30
21
## Create an RR instance
31
22
@@ -37,9 +28,12 @@ import (
37
28
" github.com/roadrunner-server/roadrunner/v2024/lib"
38
29
)
39
30
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
+
43
37
```
44
38
45
39
{% endcode %}
@@ -52,79 +46,35 @@ You can, however, choose only the plugins you want and add your own private plug
52
46
{% code title="main.go" %}
53
47
54
48
``` 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
+ )
81
56
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)
92
73
}
93
- rr , err := roadrunner.NewRR (" .rr.yaml" , overrides, plugins)
94
74
```
95
75
96
76
{% endcode %}
97
77
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 %}
128
78
129
79
## Starting & Stopping Embedded Roadrunner
130
80
@@ -143,36 +93,4 @@ go func() {
143
93
144
94
` rr.Serve() ` will block until it returns an error or ` nil ` if it was stopped gracefully.
145
95
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