samuelnogueira/zend-expressive-swoole

This package is abandoned and no longer maintained. The author suggests using the zendframework/zend-expressive-swoole package instead.

Swoole HTTP server integration with Zend Expressive framework

0.3.3 2018-06-06 16:11 UTC

This package is auto-updated.

Last update: 2022-02-01 13:11:56 UTC


README

There is now an official Zend library for integrating swoole with zend expressive: https://github.com/zendframework/zend-expressive-swoole/

Packagist Pre Release Scrutinizer Code Quality Code Coverage Build Status CircleCI Code Intelligence Status

Swoole HTTP server integration with Zend Expressive framework

Requirements

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?