swoole / library
Library of Swoole
Installs: 3 507
Dependents: 1
Suggesters: 4
Security: 0
Stars: 239
Watchers: 29
Forks: 56
Open Issues: 3
Requires
- php: >=8.1
- ext-swoole: >=5.1
- nikic/php-parser: ^5.2
Requires (Dev)
- ext-curl: *
- ext-json: *
- ext-redis: *
- ext-sockets: *
- phpunit/phpunit: ~10.0 || ~11.0
- swoole/ide-helper: dev-master
Suggests
- ext-curl: Required to use http client
- ext-mysqli: Required to use mysqli database
- ext-pdo: Required to use pdo database
- ext-redis: Required to use redis database, and the required version is greater than or equal to 3.1.3
This package is auto-updated.
Last update: 2024-11-05 06:07:13 UTC
README
Dockerized Local Development
First, run one of the following commands to install development packages using Composer:
docker run --rm -v "$(pwd)":/var/www -ti phpswoole/swoole composer update -n # or, use the official Composer Docker image: docker run --rm -v "$(pwd)":/app -ti composer update -n --ignore-platform-reqs # or, use the local Composer if installed: composer update -n --ignore-platform-reqs
Next, you need to start Docker containers:
docker compose up -d
Alternatively, if you need to rebuild some Docker image and to restart the containers:
docker compose build --progress plain --no-cache docker compose up -d --force-recreate
Now you can create a bash
session in the app
container:
docker compose exec app bash
And run commands inside the container:
composer test
Or you can run commands directly inside the app
container:
docker compose exec app composer test
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 compose exec app php examples/mysqli/base.php docker compose exec app php examples/pdo/base.php docker compose exec app 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 compose exec app php examples/fastcgi/greeter/call.php docker compose exec app php examples/fastcgi/greeter/client.php docker compose exec app php examples/fastcgi/proxy/base.php docker compose exec app php examples/fastcgi/var/client.php
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.