PHPackages                             sdpmlab/codeigniter4-roadrunner - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. sdpmlab/codeigniter4-roadrunner

ActiveLibrary

sdpmlab/codeigniter4-roadrunner
===============================

Make Codeigniter4 work on Roadrunner Server.

v1.3.1(3y ago)349014[1 PRs](https://github.com/SDPM-lab/Codeigniter4-Roadrunner/pulls)MITPHPPHP ^7.4 || ^8.0

Since Jun 28Pushed 3y ago3 watchersCompare

[ Source](https://github.com/SDPM-lab/Codeigniter4-Roadrunner)[ Packagist](https://packagist.org/packages/sdpmlab/codeigniter4-roadrunner)[ RSS](/packages/sdpmlab-codeigniter4-roadrunner/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (18)Used By (0)

Codeigniter4-Roadrunner
=======================

[](#codeigniter4-roadrunner)

 [![logo](https://camo.githubusercontent.com/af97f58a078ed8651f64259910e007809c7306067e40c07b4226b8a5c4202042/68747470733a2f2f692e696d6775722e636f6d2f73436a6553546f2e706e67)](https://camo.githubusercontent.com/af97f58a078ed8651f64259910e007809c7306067e40c07b4226b8a5c4202042/68747470733a2f2f692e696d6775722e636f6d2f73436a6553546f2e706e67)

[![Latest Stable Version](https://camo.githubusercontent.com/eb3f6b3b6b27d0820d5147b3dc0762862c995a891ada4aa0b0ee08afdfa1759c/68747470733a2f2f706f7365722e707567782e6f72672f7364706d6c61622f636f646569676e69746572342d726f616472756e6e65722f76)](//packagist.org/packages/sdpmlab/codeigniter4-roadrunner) [![Total Downloads](https://camo.githubusercontent.com/af0b62119873253de45049d839c2a763586f9438d84d9287a701de3be8fae825/68747470733a2f2f706f7365722e707567782e6f72672f7364706d6c61622f636f646569676e69746572342d726f616472756e6e65722f646f776e6c6f616473)](//packagist.org/packages/sdpmlab/codeigniter4-roadrunner) [![Latest Unstable Version](https://camo.githubusercontent.com/ab606d8f1c214f38e9398a8a6a25c7d93739f61755b77c304672818c2018842a/68747470733a2f2f706f7365722e707567782e6f72672f7364706d6c61622f636f646569676e69746572342d726f616472756e6e65722f762f756e737461626c65)](//packagist.org/packages/sdpmlab/codeigniter4-roadrunner) [![License](https://camo.githubusercontent.com/3c00572bb57b8526da15747863d30da1be1534a5d5e2617b4bcc53366d4b40aa/68747470733a2f2f706f7365722e707567782e6f72672f7364706d6c61622f636f646569676e69746572342d726f616472756e6e65722f6c6963656e7365)](//packagist.org/packages/sdpmlab/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](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.

[正體中文說明書](README_zh-TW.md)

Install
-------

[](#install)

### Prerequisites

[](#prerequisites)

1. CodeIgniter Framework 4.2.0^
2. Composer
3. Enable `php-curl` extension
4. Enable `php-zip` extension
5. Enable `php-sockets` extension

### Composer Install

[](#composer-install)

Use "Composer" to download the library and its dependencies to the project

```
composer require sdpmlab/codeigniter4-roadrunner

```

Initialize Roadrunner and files using built-in commands in the library

```
php spark ciroad:init

```

Run
---

[](#run)

Run the command in the root directory of your project:

1. Use Roadrunner command in Windows

```
rr.exe serve -d

```

3. Use Roadrunner command in MacOS/Linux

```
./rr serve -d

```

Server Settings
---------------

[](#server-settings)

The server settings are all in the project root directory ".rr.yaml". The default file will look like this:

```
version: "2.7"

rpc:
  listen: tcp://127.0.0.1:6001

server:
  command: "php psr-worker.php"
  # env:
  #   XDEBUG_SESSION: 1

http:
  address: "0.0.0.0:8080"
  static:
    dir: "./public"
    forbid: [".htaccess", ".php"]
  pool:
    num_workers: 1
    # max_jobs: 64
    # debug: true

# reload:
#   interval: 1s
#   patterns: [ ".php" ]
#   services:
#     http:
#       recursive: true
#       ignore: [ "vendor" ]
#       patterns: [ ".php", ".go", ".md" ]
#       dirs: [ "." ]
```

You can create your configuration file according to the [Roadrunner document](https://roadrunner.dev/docs/intro-config).

Development Suggestions
-----------------------

[](#development-suggestions)

### Automatic reload

[](#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.

```
reload:
  interval: 1s
  patterns: [ ".php" ]
  services:
    http:
      recursive: true
      ignore: [ "vendor" ]
      patterns: [ ".php", ".go", ".md" ]
      dirs: [ "." ]
```

The `reload` function is very resource-intensive, please do not activate the option in the formal environment.

### Using Codeigniter4 Request and Response object

[](#using-codeigniter4-request-and-response-object)

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`.

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](https://codeigniter.com/user_guide/outgoing/response.html), to conduct setting.

### Use return to stop controller logic

[](#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:

```
