Клиент websocket на php

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

A simple WebSocket WAMP client implemented in PHP

License

gabrielbull/php-websocket-client

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Читайте также:  Размер фона ссылки css

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

A simple WebSocket WAMP client implemented in PHP.

This is an implementation of WAMP version 1. I have not had the time to implement WAMP 2, but if you do, that would be awesome.

It is recommended that you install the WebSocket client library through composer.

< "require": < "gabrielbull/websocket-client": "dev-master" > >

Here is an example of a simple WebSocket client:

use WebSocketClient\WebSocketClient; use WebSocketClient\WebSocketClientInterface; class Client implements WebSocketClientInterface < private $client; public function onWelcome(array $data) < >public function onEvent($topic, $message) < >public function subscribe($topic) < $this->client->subscribe($topic); > public function unsubscribe($topic) < $this->client->unsubscribe($topic); > public function call($proc, $args, Closure $callback = null) < $this->client->call($proc, $args, $callback); > public function publish($topic, $message) < $this->client->publish($topic, $message); > public function setClient(WebSocketClient $client) < $this->client = $client; > > $loop = React\EventLoop\Factory::create(); $client = new WebSocketClient(new Client, $loop); $loop->run();

About

A simple WebSocket WAMP client implemented in PHP

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

WebSocket client and server in PHP

License

Textalk/websocket-php

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Websocket Client and Server for PHP

This library contains WebSocket client and server for PHP.

The client and server provides methods for reading and writing to WebSocket streams. It does not include convenience operations such as listeners and implicit error handling.

Preferred way to install is with Composer.

composer require textalk/websocket 
  • Current version support PHP versions ^7.4|^8.0 .
  • For PHP 7.2 and 7.3 support use version 1.5 .
  • For PHP 7.1 support use version 1.4 .
  • For PHP ^5.4 and 7.0 support use version 1.3 .

The client can read and write on a WebSocket stream. It internally supports Upgrade handshake and implicit close and ping/pong operations.

$client = new WebSocket\Client("ws://echo.websocket.org/"); $client->text("Hello WebSocket.org!"); echo $client->receive(); $client->close();

The library contains a rudimentary single stream/single thread server. It internally supports Upgrade handshake and implicit close and ping/pong operations.

Note that it does not support threading or automatic association ot continuous client requests. If you require this kind of server behavior, you need to build it on top of provided server implementation.

$server = new WebSocket\Server(); $server->accept(); $message = $server->receive(); $server->text($message); $server->close();

Fredrik Liljegren, Armen Baghumian Sankbarani, Ruslan Bekenev, Joshua Thijssen, Simon Lipp, Quentin Bellus, Patrick McCarren, swmcdonnell, Ignas Bernotas, Mark Herhold, Andreas Palm, Sören Jensen, pmaasz, Alexey Stavrov, Michael Slezak, Pierre Seznec, rmeisler, Nickolay V. Shmyrev, Christoph Kempen, Marc Roberts, Antonio Mora, Simon Podlipsky, etrinh.

About

WebSocket client and server in PHP

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

paragi/PHP-websocket-client

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Use PHP to connect to at websocket service. These 3 methods make the websocket negotiation and connection and handle the hybi10 frame encoding required.

Note : unlike the library ratchetphp/Pawl, this a synchronous library that could be used within blocking kernels like Symfony for example.

try < $sp = new \Paragi\PhpWebsocket\Client('echo.websocket.org',80) ); $sp->write("hello server"); echo "Server responded with: " . $sp->read(); > catch (\Paragi\PhpWebsocket\ConnectionException $e) < echo "Something gets wrong ".$e->getMessage(); >

Example 2, using a session cookie and setting timeout:

try < $headers = ["Cookie: SID=".session_id()]; $sp = new \Paragi\PhpWebsocket\Client('echo.websocket.org',80,$headers,$errstr,16); $bytes_written = $sp->write("hello server"); $data = $sp->read(); echo "Server responded with: ". $data; > catch (\Paragi\PhpWebsocket\ConnectionException $e) < echo "Something gets wrong ".$e->getMessage(); >
try < $sp = new \Paragi\PhpWebsocket\Client('echo.websocket.org',443,'',$errstr, 10,true) ) < $sp->write("hello server"); echo "Server responded with: " . $sp->read(); > catch (\Paragi\PhpWebsocket\ConnectionException $e) < echo "Something gets wrong ".$e->getMessage(); >

Open websocket connection

__construct( string $host [, int $port [, array $additional_headers [, string &error_string [, int $timeout [, resource $context]]]]] )

host A host URL. It can be a domain name like www.example.com or an IP address like local host: 127.0.0.1

port The servers port number

headers (optional) additional HTTP headers to attach to the request. For example to parse a session cookie.

error_string (optional) A referenced variable to store error messages, if any.

timeout (optional) The maximum time in seconds, a read operation will wait for an answer from the server. Default value is 10 seconds.

context (optional) A stream context resource created with stream_context_create() used to set various socket stream options.

Send data to server through the websocket, using hybi10 frame encoding.

int write( string $data [, boolean $final])

data Data to transport to server

final (optional) indicate if this block is the final data block of this request. Default true

Read data through websocket from the server, using hybi10 frame encoding.

string read([ string &error_string])

error_string (optional) A referenced variable to store error messages, i any.

  • This implementation waits for the final chunk of data, before returning.
  • Reading data while handling/ignoring other kind of packages

If anything goes wrong (connection, write, read. ), a ConnectionException is thrown back. Please catch them all to return a comprehensive message (here’s is a sample in a Symfony context) :

try < $sp = new \Paragi\PhpWebsocket\Client($this->localIp, $this->wsPort, ['X-Pusher: Symfony']); $sp->write($data); $reading = $sp->read(); $ret pl-s">Server responded with: $reading"; return new JsonResponse(['level' => 'success', 'message' => $ret], Response::HTTP_OK); > catch (ConnectionException $ex) < return new JsonResponse(['level' => 'error', 'message' => $ex->getMessage()], Response::HTTP_SERVICE_UNAVAILABLE); >

Tests are running against a local echo server implemented with Ratchet. You’ll have to manually start the server in ANOTHER process.

$ php tests/bin/echoserver.php

And now you can launch PhpUnit

$ phpdbg -qrr vendor/bin/phpunit $ firefox .coverage/index.html

Please let me know if there is any problems with the code. Any contributions are accepted, if the code looks nice, not bloated and otherwise reasonable.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Async WebSocket client for PHP based on Amp.

License

amphp/websocket-client

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

amphp/websocket-client is an async WebSocket client for PHP based on Amp.

This package can be installed as a Composer dependency.

composer require amphp/websocket-client 

More extensive code examples reside in the examples directory.

use Amp\Websocket\Client\WebsocketHandshake; use function Amp\Websocket\Client\connect; // Connects to the websocket endpoint at libwebsockets.org which sends a message every 50ms. $handshake = (new WebsocketHandshake('wss://libwebsockets.org')) ->withHeader('Sec-WebSocket-Protocol', 'dumb-increment-protocol'); $connection = connect($handshake); while ($message = $connection->receive()) < $payload = $message->buffer(); printf("Received: %s\n", $payload); if ($payload === '100') < $connection->close(); break; > >

amphp/websocket-client follows the semver semantic versioning specification like all other amphp packages.

If you discover any security related issues, please email contact@amphp.org instead of using the issue tracker.

The MIT License (MIT). Please see LICENSE for more information.

About

Async WebSocket client for PHP based on Amp.

Источник

Оцените статью