narenknn / websocket
WebSocket client and server
Requires
- php: ^7.4 | ^8.0
- phrity/net-uri: ^1.0
- phrity/util-errorhandler: ^1.0
- psr/http-message: ^2.0
- psr/log: ^1.0 | ^2.0 | ^3.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2026-03-03 13:51:49 UTC
README
Description
This project was forked from archived project Textalk/websocket-php and upgraded with non-blocking reads. Primary goal is to use only the client for non-blocking reads (server is largely left unchanged, but the state is not checked anymore). Non-blocking reads is enabled for client by default and returns empty message immediately. This feature is useful, if one has a threading mechanism already and just want to check for received messages.
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.
Documentation
Installing
Preferred way to install is with Composer.
composer require textalk/websocket
- Current version support PHP versions
^7.4|^8.0. - For PHP
7.2and7.3support use version1.5. - For PHP
7.1support use version1.4. - For PHP
^5.4and7.0support use version1.3.
Client
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();
Server
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();
License and Contributors
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.