nekland/woketo

该软件包已被放弃,不再维护。未建议替代软件包。

PHP的WebSocket库

2.2.1 2018-12-06 09:56 UTC

README

⚠️ 由于使用率低(几乎没有人使用),我将不会努力使其与PHP 8兼容。因此,该库已弃用,您不应使用它。⚠️

PHP WebSocket库。具有以下功能:

  • 服务器
  • 客户端
  • 支持WSS(通过SSL的WebSocket)
  • Autobahn测试套件通过(WebSocket测试套件参考)
  • 支持二进制/文本消息
  • 基于reactphp(异步套接字通信)构建
  • 不依赖于任何其他大型框架/库,这意味着您可以使用它与guzzle(任何版本)或Symfony(任何版本)一起使用
  • Woketo遵循semver

Build Status Scrutinizer Code Quality Code Coverage

需求

  • PHP 7+

如何安装

# The installation is pretty much easier with composer. But you still can use it as git submodule !
composer require "nekland/woketo"

这就完了!🙀

如何使用

文件 tests.php 是一个基本的echo服务器。这就是您使用Woketo创建WebSocket服务器所需的所有内容

<?php

use Your\Namespace\YourMessageHandler;
use Nekland\Woketo\Server\WebSocketServer;

$server = new WebSocketServer(1337);
$server->setMessageHandler(new YourMessageHandler(), '/path'); // accessible on ws://127.0.0.1:1337/path
$server->start(); // And that's all <3
<?php
// YourMessageHandler.php

namespace Your\Namespace;

use Nekland\Woketo\Core\AbstractConnection;
use Nekland\Woketo\Message\TextMessageHandler;

class YourMessageHandler extends TextMessageHandler
{
    public function onConnection(AbstractConnection $connection)
    {
        // Doing something when the client is connected ?
        // This method is totally optional.
    }
    
    public function onMessage(string $data, AbstractConnection $connection)
    {
        // Sending back the received data
        $connection->write($data);
    }
    
    public function onDisconnect(AbstractConnection $connection)
    {
        // Doing something when the connection between client/server is disconnecting
        // Optionnal
    }
}

如何测试

单元测试套件

git clone git@github.com:Nekland/Woketo
cd Woketo
composer install
./bin/phpunit

功能测试套件

服务器测试套件

php tests/echo-server.php
wstest -m fuzzingclient

客户端测试套件

wstest -m fuzzingserver
php tests/client_autobahn.php

wstest是Autobahn测试工具。您可以使用sudo pip install autobahntestsuite安装它。

您可以在他们的文档中了解更多关于Autobahn安装的信息。

如何做其他事情?

接下来是什么?

您可以在github里程碑中查看下一版本的计划。

Woketo不做什么?

目前不支持以下内容

  • WebSocket 扩展,目前不支持,但可能在未来会支持
  • WAMP 的实现可能永远不会由 Woketo 自己完成,因为它是建立在 WebSocket 之上的一个层。这包括 JSON-RPC 以及 WebSocket 以上的其他层。

感谢

感谢所有代码贡献者(你好 folliked =)). 以及任何代码审查者(嗨 valanz)。

<3