samuelnogueira / zend-expressive-swoole
Swoole HTTP server integration with Zend Expressive framework
Requires
- php: ^7.1
- ext-swoole: ^2.0
- dflydev/fig-cookies: ^1.0
- psr/container: ^1.0
- psr/http-server-middleware: ^1.0
- zendframework/zend-diactoros: ^1.7
Requires (Dev)
- eaglewu/swoole-ide-helper: dev-master
- guzzlehttp/guzzle: ^6.3
- phpunit/php-code-coverage: ^5.3 || ^6.0
- phpunit/phpunit: ^6.3 || ^7.0
- squizlabs/php_codesniffer: ^3.0
- symfony/process: ^3.4 || ^4.0
- zendframework/zend-config-aggregator: ^1.1
- zendframework/zend-expressive: ^3.0
- zendframework/zend-expressive-fastroute: ^3.0
- zendframework/zend-expressive-router: ^3.0
- zendframework/zend-servicemanager: ^3.3
Suggests
- ext-inotify: Needed for hot code reload
README
There is now an official Zend library for integrating swoole with zend expressive: https://github.com/zendframework/zend-expressive-swoole/
Swoole HTTP server integration with Zend Expressive framework
Requirements
- PHP >= 7.1
- ext-swoole >= 2.0
- Zend Expressive v3 application
Support for older version v2 of Zend Expressive is provided in version 0.2 of this library.
Installation
This package is installable and autoloadable via Composer as samuelnogueira/zend-expressive-swoole.
composer require samuelnogueira/zend-expressive-swoole
Configuration
<?php // config/autoload/swoole.global.php return [ 'swoole_http_server' => [ 'host' => '127.0.0.1', // default is '0.0.0.0' 'port' => 80, // default is 8080 'settings' => [ // default is []. See see https://rawgit.com/tchiotludo/swoole-ide-helper/english/docs/classes/swoole_server.html#method_set 'http_parse_post' => false, 'worker_num' => 100, ], 'hot_code_reload' => [ 'enabled' => true, // default is false 'interval' => 500, // default is 1000. Milliseconds between file changes checks. ], ], ];
Any omitted config key will fallback to the default value in the comments above.
Usage
# Start swoole HTTP booting your Zend Expressive app
$ ./vendor/bin/swoole
Hot Code Reload
To enable hot code reload, add the following configuration:
<?php // config/autoload/swoole.global.php return [ 'swoole_http_server' => [ // (...) 'hot_code_reload' => [ 'enabled' => true, ], ], ];
With this feature enabled, each swoole worker will keep track of included PHP files using inotify, and will restart all workers if a file is changed.
This serves to enable easier development when using swoole server.
Do not use this feature in production. It doesn't perform well for a big number of workers, nor is it safe.
TODO
-
Cookies retrievable via \Psr\Http\Message\ServerRequestInterface::getCookieParams -
Configurable number of workers -
Hot code reload -
Add support for Zend Expressive 3 - Include
Cookie
header in generated PSR-7 Server Request - Handle uploaded files
- Stream request body instead of buffering it
-
Stream response body instead of buffering it - Windows support?