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
Codeigniter4-RoadRunner provides the synchroniztion of the Request and Response object between Roadrunner-Worker and Codeigniter4. Since Codeigniter4 doesn't implement [PSR-7 standard](https://codeigniter.tw/user_guide/intro/psr.html) completely, you need to use this library to allow your Codeigniter4 project to run using RoadRunner Server.
10
10
11
11
> This library is currently under development, and its functions are not yet stable. Do not use it in production environment.
Initialize Roadrunner and files using built-in commands in the library
25
29
@@ -31,7 +35,7 @@ php spark ciroad:init
31
35
Run the command in the root directory of your project:
32
36
1. Use Codeigniter4 spark command
33
37
```
34
-
php spark ciroad:start
38
+
php spark ciroad:start -v -d
35
39
```
36
40
2. Use Roadrunner command in Windows
37
41
```
@@ -44,7 +48,7 @@ Run the command in the root directory of your project:
44
48
45
49
## Server Settings
46
50
The server settings are all in the project root directory ".rr.yaml". The default file will look like this:
47
-
```
51
+
```yaml
48
52
http:
49
53
address: 0.0.0.0:8080
50
54
workers:
@@ -58,4 +62,217 @@ static:
58
62
dir: "public"
59
63
forbid: [".php", ".htaccess"]
60
64
```
61
-
You can create your configuration file according to the [Roadrunner document](https://roadrunner.dev/docs).
65
+
You can create your configuration file according to the [Roadrunner document](https://roadrunner.dev/docs/intro-config).
66
+
67
+
## Development Suggestions
68
+
69
+
### Automatic reload
70
+
71
+
In the default circumstance of RoadRunner, you must restart the server everytime after you revised any PHP files so that your revision will effective.
72
+
It seems not that friendly during development.
73
+
74
+
You can revise your `.rr.yaml` configuration file, add the settings below and start the development mode with `-v -d`.
75
+
RoadRunner Server will detect if the PHP files were revised or not, automatically, and reload the Worker instantly.
76
+
77
+
```yaml
78
+
# reload can reset rr servers when files change
79
+
reload:
80
+
#refresh interval (default 1s)
81
+
interval: 1s
82
+
#file extensions to watch, defaults to [.php]
83
+
patterns: [".php"]
84
+
```
85
+
86
+
The `reload` function is very resource-intensive, please do not activate the option in the formal environment.
87
+
88
+
### Using Codeigniter4 Request and Response object
89
+
90
+
Codeigniter4 does not implement the complete [HTTP message interface](https://www.php-fig.org/psr/psr-7/), hence this library focuses on the synchronize of `PSR-7 interface` and `Codeigniter4 HTTP interface`.
91
+
92
+
Base on the reasons above, You should use `$this->request`, provided by Codeigniter4, or the global function `/Config/Services::('request')` to fetch the correct request object; Use `$this->response` or `/Config/Services::('response')` to fetch the correct response object.
93
+
94
+
Please be noticed, while constructing response for the users during developing, you should prevent using PHP built-in methods to conduct `header` or `set-cookies` settings. Using the `setHeader()` and `setCookie()`, provided by the [Codeigniter4 Response Object](https://codeigniter.com/user_guide/outgoing/response.html), to conduct setting.
95
+
96
+
### Use return to stop controller logic
97
+
98
+
Inside the Controller, try using return to stop the controller logic. No matter the response of view or API, reduce the `echo` output usage can avoid lets of errors, just like ths:
We only focus on supporting the Codeigniter4 built-in [Session library](https://codeigniter.com/user_guide/libraries/sessions.html), and do not guarantee if using `session_start()` and `$_SEEEION` can work as normal. So, you should avoid using the PHP built-in Session method, change to the Codeigniter4 framework built-in library.
131
+
132
+
### Developing and debugging in a environment with only one Worker
133
+
134
+
Since the RoadRunner has fundamentally difference with other server software(i.e. Nginx, Apache), every Codeigniter4 will persist inside RAMs as the form of Worker, HTTP requests will reuse these Workers to process. Hence, we have better develop and test stability under the circumstance with only one Worker to prove it can also work properly under serveral Workers in the formal environment.
135
+
136
+
You can reference the `.rr.yaml` settings below to lower the amount of Worker to the minimum:
137
+
138
+
```yaml
139
+
http:
140
+
address: 0.0.0.0:8080
141
+
workers:
142
+
command: "php psr-worker.php"
143
+
pool:
144
+
numWorkers: 1
145
+
maxJobs: 1
146
+
```
147
+
148
+
# Global Methods
149
+
150
+
We offer some Global methods to help you develop your projects more smoothly.
151
+
152
+
### Dealing with the file uploading
153
+
154
+
Since the RoadRunner Worker can not transfer the correct `$_FILES` context, the Codeigniter4 file upload class will not be able to work properly. To solve this, we offered a file upload class corresponding the PSR-7 standard for you to deal with file uploading correctly within RoadRunner. Even if you switched your project to another server environment(i.e. spark serve, Apache, Nginx), this class can still work properly, and doesn't need any code modification.
155
+
156
+
You can fetch the uploaded files by means of `SDPMlab\Ci4Roadrunner\UploadedFileBridge::getPsr7UploadedFiles()` in the controller (or any other places). This method will return an array, consist of Uploaded File objects. The available methods of this object is identical as the regulation of [PSR-7 Uploaded File Interface](https://www.php-fig.org/psr/psr-7/#36-psrhttpmessageuploadedfileinterface).
If you encountered some variables or object content that needed to be confirmed in `-v -d` development mode, you can use the global function `dump()` to throw errors onto the terminal no matter where the program is.
209
+
210
+
```php
211
+
/**
212
+
* Dump given value into target output.
213
+
*
214
+
* @param mixed $value Variable
215
+
* @param string $target Possible options: OUTPUT, RETURN, ERROR_LOG, LOGGER.
216
+
* @return string|null
217
+
*/
218
+
function dump($value,string $target = "ERROR_LOG") : ?string;
219
+
```
220
+
221
+
## Avaliable commands
222
+
223
+
### ciroad:init
224
+
225
+
Initiallize RoadRunner and its needed files.
226
+
227
+
* Use
228
+
```
229
+
$ php spark ciroad:init
230
+
```
231
+
232
+
### ciroad:start
233
+
234
+
Start RoadRunner Server
235
+
236
+
* Use
237
+
```
238
+
$ php spark ciroad:start [Options]
239
+
```
240
+
241
+
* Options:
242
+
```
243
+
-d During debugging mode, HTTP requests details will be listed on the terminal
0 commit comments