Skip to content

Commit

Permalink
Merge pull request #19 from monkenWu/dev
Browse files Browse the repository at this point in the history
v0.3.0
  • Loading branch information
monkenWu authored Dec 23, 2022
2 parents 2ef40b7 + c244783 commit 7f15a38
Show file tree
Hide file tree
Showing 24 changed files with 208 additions and 1,460 deletions.
84 changes: 42 additions & 42 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
name: phpunit
on:
pull_request:
branches: [ main, dev ]
jobs:
# name: phpunit
# on:
# pull_request:
# branches: [ main, dev ]
# jobs:

tests:
runs-on: ubuntu-22.04
if: "!contains(github.event.head_commit.message, '[ci skip]')"
name: ${{ matrix.driver }}-PHP ${{ matrix.php-ver }}
# tests:
# runs-on: ubuntu-22.04
# if: "!contains(github.event.head_commit.message, '[ci skip]')"
# name: ${{ matrix.driver }}-PHP ${{ matrix.php-ver }}

strategy:
fail-fast: false
matrix:
php-ver: ['8.0','8.1']
driver: ['RoadRunner', 'Workerman']
# strategy:
# fail-fast: false
# matrix:
# php-ver: ['8.0','8.1']
# driver: ['RoadRunner', 'Workerman']

steps:
- name: Checkout
uses: actions/checkout@v2
# steps:
# - name: Checkout
# uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-ver }}
coverage: xdebug
extensions: curl, dev, mbstring, zip, sockets, fpm, intl, posix
env:
GITHUB_TOKEN: ${{ secrets.COMPOSER_AUTH }}
# - name: Setup PHP
# uses: shivammathur/setup-php@v2
# with:
# php-version: ${{ matrix.php-ver }}
# coverage: xdebug
# extensions: curl, dev, mbstring, zip, sockets, fpm, intl, posix
# env:
# GITHUB_TOKEN: ${{ secrets.COMPOSER_AUTH }}

- name: Install dependencies
working-directory: ./dev
run: |
composer install --prefer-dist --no-progress --no-suggest
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
# - name: Install dependencies
# working-directory: ./dev
# run: |
# composer install --prefer-dist --no-progress --no-suggest
# env:
# COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

- name: Init Burner
working-directory: ./dev
run: |
php spark burner:init ${{ matrix.driver }}
php spark burner:start &
# - name: Init Burner
# working-directory: ./dev
# run: |
# php spark burner:init ${{ matrix.driver }}
# php spark burner:start &

- name: Test with PHPUnit
working-directory: ./dev
run: |
vendor/bin/phpunit -v
env:
TERM: xterm-256color
# - name: Test with PHPUnit
# working-directory: ./dev
# run: |
# vendor/bin/phpunit -v
# env:
# TERM: xterm-256color
193 changes: 23 additions & 170 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,172 +10,49 @@ Burner is an out-of-the-box library for CodeIgniter4 that supports [RoadRunner](
1. CodeIgniter Framework 4.2.0^
2. Composer
3. PHP8^
4. Enable `php-curl` extension
5. Enable `php-zip` extension
6. Enable `php-sockets` extension
7. Enable `php-pcntl` extension
8. Enable `php-posix` extension
9. If you use `Workerman` driver. We recommend you to install [php-event](https://www.php.net/manual/en/book.event.php) extension
10. If you use `OpenSwoole` driver. Please read [How to Install Open Swoole](https://openswoole.com/docs/get-started/installation)

### Composer Install

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

```
composer require monken/codeigniter4-burner
```

Initialize Server files using built-in commands in the library
You can install the appropriate Driver according to your preference.

```
php spark burner:init [RoadRunner, Workerman, OpenSwoole]
```
Each Driver has its own development rules to be aware of, as well as some proprietary server commands, which you can find in their Git repository README files.

## Run
Run the command in the root directory of your project:
* [OpenSwoole Driver](https://github.com/monkenWu/CodeIgniter4-Burner-OpenSwoole)

```
php spark burner:start
```
```
composer require monken/codeigniter4-burner-OpenSwoole
```
* [RoadRunner Driver](https://github.com/monkenWu/CodeIgniter4-Burner-RoadRunner)

## RoadRunner Server Settings

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

```yaml
version: "2.7"

rpc:
listen: tcp://127.0.0.1:6001

server:
command: "php Worker.php"
# env:
# XDEBUG_SESSION: 1

http:
address: "0.0.0.0:8080"
static:
dir: "/app/dev/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", ".dmd" ]
# dirs: [ "/app/dev" ]
```

You can create your configuration file according to the [Roadrunner document](https://roadrunner.dev/docs/intro-config).
```
composer require monken/codeigniter4-burner-RoadRunner
```

## Workerman Server Settings
* [Workerman Driver](https://github.com/monkenWu/CodeIgniter4-Burner-Workerman)

The server settings are all in the `app/Config` directory `Workerman.php`. The default file will look like this:

```php
class Workerman extends BaseConfig
{
/**
* Public static files location path.
*
* @var string
*/
public $staticDir = '/app/dev/public';
```
composer require monken/codeigniter4-burner-Workerman
```

/**
* Public access to files with these filename-extension is prohibited.
*
* @var array
*/
public $staticForbid = ['htaccess', 'php'];
After installing the driver, initialize the server files using the built-in commands in the library

/** hide **/
}
```

You can create your configuration file according to the [Workerman document](https://www.workerman.net/doc/workerman/worker/count.html).

## OpenSwoole Server Settings

The server settings are all in the `app/Config` directory `OpenSwoole.php`. The default file will look like this:

```php
class OpenSwoole extends BaseConfig
{
/**
* TCP HTTP service listening ip
*
* @var string
*/
public $listeningIp = '0.0.0.0';

/**
* TCP HTTP service listening port
*
* @var int
*/
public $listeningPort = 8080;

/**
* SWOOLE_PROCESS or SWOOLE_BASE
*
* @var int
*
* @see https://openswoole.com/docs/modules/swoole-server-reload#server-modes-and-reloading
*/
public $mode = SWOOLE_BASE;

//hide
}
php spark burner:init [RoadRunner, Workerman, OpenSwoole]
```

You can refer to the [OpenSwoole HTTP Server Settings](https://openswoole.com/docs/modules/swoole-http-server/configuration), [OpenSwoole TCP Server Settings](https://openswoole.com/docs/modules/swoole-server/configuration), etc. to crete a configuration profile that meets your project requirements.

## Development Suggestions

### Automatic reload

In the default circumstance of RoadRunner and Workerman, 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.

#### RoadRunner

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.
## Run
Run the command in the root directory of your project:

```yaml
reload:
interval: 1s
patterns: [ ".php" ]
services:
http:
recursive: true
ignore: [ "vendor" ]
patterns: [ ".php", ".go", ".md" ]
dirs: [ "." ]
```
#### Workerman
You can modify your `app/Config/Workerman.php` configuration file, add the following settings and restart the server.

```php
public $autoReload = true;
php spark burner:start [RoadRunner, Workerman, OpenSwoole]
```

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

#### OpenSwoole

> Burner does not currently support automatic loading of OpenSwoole drivers.
## Development Suggestions

### Using Codeigniter4 Request and Response object

Expand All @@ -187,7 +64,7 @@ Please be noticed, while constructing response for the users during developing,

### 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:
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:W

```php
<?php namespace App\Controllers;
Expand Down Expand Up @@ -223,31 +100,7 @@ We only focus on supporting the Codeigniter4 built-in [Session library](https://

### Developing and debugging in a environment with only one Worker

Since the RoadRunner and Workerman 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.

#### RoadRunner

You can reference the `.rr.yaml` settings below to lower the amount of Worker to the minimum:

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

#### Workerman

You can reference the `app/Config/Workerman.php` settings below to lower the amount of Worker to the minimum:

```php
public $workerCount = 1;
```
Since the RoadRunner, OpenSwoole and Workerman 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.

### Database Connection

Expand Down
Loading

0 comments on commit 7f15a38

Please sign in to comment.