Symfony integration with Swoole to speed up your applications.
CI Job | Branch master |
Branch develop |
---|---|---|
Circle | ||
CodeCov | ||
Travis |
-
Make sure you have installed proper Swoole PHP Extension and pass other requirements.
-
(optional) Create a new symfony project
composer create-project symfony/skeleton project cd ./project
-
Install bundle in your Symfony application
composer require k911/swoole-bundle
-
Edit
config/bundles.php
return [ // ...other bundles K911\Swoole\Bridge\Symfony\Bundle\SwooleBundle::class => ['all' => true], ];
-
Run Swoole HTTP Server
bin/console swoole:server:run
-
Enter http://localhost:9501
-
You can now configure bundle according to your needs
-
Built-in API Server
Swoole Bundle API Server allows managing Swoole HTTP Server in real-time.
- Reload worker processes
- Shutdown server
- Access metrics and settings
-
Improved static files serving
Swoole HTTP Server provides a default static files handler, but it lacks supporting many
Content-Types
. To overcome this issue, there is (not yet configurable) Advanced Static Files Server. Static files serving remains enabled by default in the development environment. Static files directory defaults to%kernel.project_dir%/public
. -
Hot Module Reload (HMR) - for development
Since Swoole HTTP Server runs in Event Loop and does not flush memory between requests, to keep DX equal with normal servers, this bundle uses code replacement technique, using
inotify
PHP Extension to allow continuous development. It is enabled by default (when the extension is found) and requires no additional configuration. You can turn it off in bundle configuration. -
Symfony Messenger integration
Available since version:
0.6
Swoole Server Task Transport has been integrated into this bundle to allow easy execution of asynchronous actions. Documentation of this feature is available here.
- PHP version
>= 7.3.10
- Swoole PHP Extension
>= 4.4.7
- Symfony
>= 4.3.1
Additional requirements to enable specific features:
- Inotify PHP Extension
^2.0.0
to use Hot Module Reload (HMR)
Bundle requires Swoole PHP Extension version 4.4.7 or higher. Active bug fixes are provided only for the latest version.
To check your installed version you can run following command:
php -r "echo swoole_version() . \PHP_EOL;"
# 4.4.7
Official GitHub repository swoole/swoole-src contains comprehensive installation guide. The recommended approach is to install it from source.