Open Swoole Library
This library works with Open Swoole since release version v4.7.1. WIP
Table of Contents
- How to Contribute
- Development
- Dockerized Local Development
- Examples
- Compatibility Patch (Swoole version <= v4.4.12)
- Coding Style Checks and Fixes
- Third Party Libraries
- License
How to Contribute
Just new pull request (and we need unit tests for new features)
Code Requirements
Development
Branches
- master: For Swoole 4.7.1+, which supports PHP 7.2+.
Dockerized Local Development
First, run following command to autoload PHP classes/files (no exra Composer packages to be installed):
docker run --rm -v "$(pwd)":/var/www -t openswoole/swoole:latest-dev composer update -n
Secondly, run next command to start Docker containers:
docker-compose up
Alternatively, if you need to rebuild the service(s) and to restart the containers:
docker-compose build --no-cache
docker-compose up --force-recreate
Now you can run unit tests included:
docker exec -t $(docker ps -qf "name=app") ./vendor/bin/phpunit
Examples
Once you have Docker containers started (as discussed in previous section), you can use commands like following to run examples under folder examples.
Examples of Database Connection Pool
docker exec -t $(docker ps -qf "name=app") bash -c "php ./examples/mysqli/base.php"
docker exec -t $(docker ps -qf "name=app") bash -c "php ./examples/pdo/base.php"
docker exec -t $(docker ps -qf "name=app") bash -c "php ./examples/redis/base.php"
Examples of FastCGI Calls
There is a fantastic example showing how to use Swoole as a proxy to serve a WordPress website using PHP-FPM. Just open URL http://127.0.0.1 in the browser and check what you see there. Source code of the example can be found here.
Here are some more examples to make FastCGI calls to PHP-FPM:
docker exec -t $(docker ps -qf "name=app") bash -c "php ./examples/fastcgi/greeter/call.php"
docker exec -t $(docker ps -qf "name=app") bash -c "php ./examples/fastcgi/greeter/client.php"
docker exec -t $(docker ps -qf "name=app") bash -c "php ./examples/fastcgi/proxy/base.php"
docker exec -t $(docker ps -qf "name=app") bash -c "php ./examples/fastcgi/var/client.php"
Compatibility Patch (Swoole version <= v4.4.12)
define('SWOOLE_USE_SHORTNAME', true); // or false (it depends on you)
Coding Style Checks and Fixes
To update Composer packages (optional):
docker run --rm -v "$(pwd)":/var/www -t openswoole/swoole:latest-dev composer update -n
To check coding standard violations:
docker run --rm -v "$(pwd)":/var/www -t openswoole/swoole bash -c "composer cs-check"
To correct coding standard violations automatically:
docker run --rm -v "$(pwd)":/var/www -t openswoole/swoole bash -c "composer cs-fix"
Third Party Libraries
Here are all the third party libraries used in this project:
- The FastCGI part is derived from Composer package lisachenko/protocol-fcgi.
You can find the licensing information of these third party libraries here.
License
This project follows the Apache 2 license.