nekland / woketo
该软件包已被放弃,不再维护。未建议替代软件包。
PHP的WebSocket库
2.2.1
2018-12-06 09:56 UTC
Requires
- php: ^7.0
- nekland/tools: ^1.0 || ^2.0
- psr/log: ^1.0
- react/dns: ^0.4.6
- react/event-loop: ^1.0.0
- react/socket: ^1.0.0
Requires (Dev)
- phpunit/phpunit: ^6.0
This package is auto-updated.
Last update: 2021-09-20 09:58:12 UTC
README
⚠️ 由于使用率低(几乎没有人使用),我将不会努力使其与PHP 8兼容。因此,该库已弃用,您不应使用它。⚠️
PHP WebSocket库。具有以下功能:
- 服务器
- 客户端
- 支持WSS(通过SSL的WebSocket)
- Autobahn测试套件通过(WebSocket测试套件参考)
- 支持二进制/文本消息
- 基于reactphp(异步套接字通信)构建
- 不依赖于任何其他大型框架/库,这意味着您可以使用它与guzzle(任何版本)或Symfony(任何版本)一起使用
- Woketo遵循semver
需求
- 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安装的信息。
如何做其他事情?
- 如何了解Woketo的使用? RTFM!
- 如何了解其内部工作原理?阅读文档/dev.md页面。
- 如何贡献?阅读文档/CONTRIBUTING.md页面。
- 如何获得支持? 使用Gitter,问题跟踪器不是论坛。
接下来是什么?
您可以在github里程碑中查看下一版本的计划。
Woketo不做什么?
目前不支持以下内容
- WebSocket 扩展,目前不支持,但可能在未来会支持
- WAMP 的实现可能永远不会由 Woketo 自己完成,因为它是建立在 WebSocket 之上的一个层。这包括 JSON-RPC 以及 WebSocket 以上的其他层。
感谢
感谢所有代码贡献者(你好 folliked =)). 以及任何代码审查者(嗨 valanz)。
<3