催化器/swoole-foundation

Catalyst Swoole 基础库

v0.1.1 2017-01-28 00:19 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:14:44 UTC


README

Swoole 基础库

什么是 Swoole 基础库

Swoole 基础库是一个工厂基础库,可以轻松创建 Swoole 服务器实例。设置和事件的编排基于闭包。

依赖关系

此包依赖于 catalyst/servant

创建 Swoole 服务器

use Catalyst\Swoole\{
    ServerFactory,
    Entities\ServerEvents,
    Entities\ServerConfiguration
};

$factory = new ServerFactory();

$server = $factory->server(function(ServerConfiguration $settings, ServerEvents $events) {
    $settings->withBinding('::', 9508);
    
    $events->onStart(function() {
        echo 'Server started!';
    });
});

创建 Swoole Http 服务器

use Catalyst\Swoole\{
    ServerFactory,
    Entities\HttpServerEvents,
    Entities\ServerConfiguration
};

$factory = new ServerFactory();

$server = $factory->httpServer(function(ServerConfiguration $settings, HttpServerEvents $events) {
    $settings->withBinding('::', 80);
    
    $events->onRequest(function(swoole_http_request $request, swoole_http_respose $response) {
        $response->end('Hello World!');
    });
});

创建 Swoole Websocket 服务器

use Catalyst\Swoole\{
    ServerFactory,
    Entities\HttpServerEvents,
    Entities\ServerConfiguration
};

$factory = new ServerFactory();

$server = $factory->webSocketServer(function(ServerConfiguration $settings, HttpServerEvents $events) {
    $settings->withBinding('::', 80);
    
    $events->onRequest(function(swoole_http_request $request, swoole_http_respose $response) {
        $response->end('Hello World!');
    });
});

服务者意识

工厂实现具有服务者意识,允许将额外的服务者链接到指定的服务者。由于实现决策,您不能替换第一个服务者。当尝试设置不同的服务者时,将抛出异常。

许可证和维护者

此包采用 MIT 许可证。此包由以下人员积极维护:

  • Matthias Kaschubowski