Download the PHP package sdpmlab/codeigniter4-roadrunner without Composer
On this page you can find all versions of the php package sdpmlab/codeigniter4-roadrunner. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sdpmlab/codeigniter4-roadrunner
More information about sdpmlab/codeigniter4-roadrunner
Files in sdpmlab/codeigniter4-roadrunner
Package codeigniter4-roadrunner
Short Description Make Codeigniter4 work on Roadrunner Server.
License MIT
Informations about the package codeigniter4-roadrunner
Codeigniter4-Roadrunner
Codeigniter4-RoadRunner provides the synchroniztion of the Request and Response object between Roadrunner-Worker and Codeigniter4. Since Codeigniter4 doesn't implement PSR-7 standard completely, you need to use this library to allow your Codeigniter4 project to run using RoadRunner Server.
正體中文說明書
Install
Prerequisites
- CodeIgniter Framework 4.2.0^
- Composer
- Enable
php-curl
extension - Enable
php-zip
extension - Enable
php-sockets
extension
Composer Install
Use "Composer" to download the library and its dependencies to the project
Initialize Roadrunner and files using built-in commands in the library
Run
Run the command in the root directory of your project:
-
Use Roadrunner command in Windows
- Use Roadrunner command in MacOS/Linux
Server Settings
The server settings are all in the project root directory ".rr.yaml". The default file will look like this:
You can create your configuration file according to the Roadrunner document.
Development Suggestions
Automatic reload
In the default circumstance of RoadRunner, you must restart the server everytime after you revised any PHP files so that your revision will effective. It seems not that friendly during development.
You can revise your .rr.yaml
configuration file, add the settings below and start the development mode with -d
.
RoadRunner Server will detect if the PHP files were revised or not, automatically, and reload the Worker instantly.
The reload
function is very resource-intensive, please do not activate the option in the formal environment.
Using Codeigniter4 Request and Response object
Codeigniter4 does not implement the complete HTTP message interface, hence this library focuses on the synchronize of PSR-7 interface
and Codeigniter4 HTTP interface
.
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.
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, to conduct setting.
Use return to stop controller logic
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:
Use the built-in Session library
We only focus on supporting the Codeigniter4 built-in Session library, 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.
Developing and debugging in a environment with only one Worker
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.
You can reference the .rr.yaml
settings below to lower the amount of Worker to the minimum:
Database Connection
We only focus on supporting the Codeigniter4 built-in Database Library, hence we do not guarantee if using the PHP built-in method should work as normal. Therefore, you should avoid using the PHP built-in database connection method but pick the Codeigniter4 framework built-in library.
Under the default situation, DB of the Worker should be lasting, and will try to reconnect once the connection is failed.
Every Request that goes into Worker is using a same DB connection instance. If you don't want this default setting but expecting
every Request to use the reconnect DB connection instance. You can add the configuration down below into the .env
file under the root directory.
Global Methods
We offer some Global methods to help you develop your projects more smoothly.
Dealing with the file uploading
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.
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.
Dealing with thrown errors
If you encountered some variables or object content that needed to be confirmed in -d
development mode, you can use the global function dump()
to throw errors onto the terminal no matter where the program is.
Avaliable commands
ciroad:init
Initiallize RoadRunner and its needed files.
- Use
RoadRunner Server Commands
For the available commands, you can refer to the instructions in the RoadRunner official document .
All versions of codeigniter4-roadrunner with dependencies
codeigniter4/framework Version ^4.2.0
spiral/roadrunner Version ^2
spiral/dumper Version ^2.8
laminas/laminas-diactoros Version ^2.8
nyholm/psr7 Version ^1.4