aguetkriegerisch / elephant.io-custom
通过PHP发送事件到实时WebSocket引擎,包括在握手时自定义头部信息
v4.2.2
2023-04-28 18:35 UTC
Requires
- php: >=7.2
- psr/log: ^1.1 || ^3.0
Requires (Dev)
- monolog/monolog: ^2.8 || ^3.0
- phpunit/phpunit: ^8.5 || ^9.5
This package is auto-updated.
Last update: 2024-09-28 21:51:23 UTC
README
___ _,.--.,_ Elephant.io is a rough websocket client
.-~ ~--"~-. ._ "-. written in PHP. Its goal is to ease the
/ ./_ Y "-. \ communications between your PHP Application and
Y :~ ! Y a real-time server.
lq p | / .|
_ \. .-, l / |j Requires PHP 5.4 and openssl, licensed under
()\___) |/ \_/"; ! the MIT License.
\._____.-~\ . ~\. ./
Y_ Y_. "vr"~ T Built-in Engines:
( ( |L j - Socket.io 4.x, 3.x, 2.x, 1.x
[nn[nn..][nn..] - Socket.io 0.x (courtesy of @kbu1564)
~~~~~~~~~~~~~~~~~~~
安装
我们建议您使用composer,以下命令: php composer.phar require elephantio/elephant.io
。对于其他方式,您可以查看发布页面,或git克隆链接。
使用方法
要使用Elephant.io与以下描述的socket服务器通信。
<?php use ElephantIO\Client; $url = 'https://:8080'; $client = new Client(Client::engine(Client::CLIENT_4X, $url)); $client->initialize(); $client->of('/'); // emit an event to the server $data = ['username' => 'my-user']; $client->emit('get-user-info', $data); // wait an event to arrive // beware when waiting for response from server, the script may be killed if // PHP max_execution_time is reached if ($packet = $client->wait('user-info')) { // an event has been received, the result will be a stdClass // data property contains the first argument // args property contains array of arguments, [$data, ...] $data = $packet->data; $args = $packet->args; // access data $email = $data['email']; }
文档
文档尚未编写,但您应该检查 示例目录 以获取关于此库如何工作的基本知识。
特别感谢
特别感谢Mark Karpeles,他帮助项目创始人理解了WebSockets的工作方式。