Simple WebSocket Client/Server for PHP
Formerly known as php-websocket
- Version: 2.0.0
- Build Status:
- Documentation: wrench.readthedocs.org
A simple websocket server and client package for PHP 5.3/5.4, using streams. Protocol support is based around RFC 6455, targeting the latest stable versions of Chrome and Firefox. (Suggest other clients here)
The new vendor namespace is Wrench. This namespace begins in the
directory, rather than
Apart from the new namespace, the public API of this new major version is fairly compatible with that of php-websocket 1.0.0.
The protected API has changed, a lot. Many method have been broken up into simple protected methods. This makes the Server class much easier to extend. In fact, almost all of the classes involved in your typical daemon can now be replaced or extended, including the socket handling and protocol handling.
What happened to the
The client-side libraries are no longer supported: some libraries are included but are packaged only as examples. You're free to use whatever client-side libraries you'd like with the server. If you're still using them, see the 1.0 branch.
The library is PSR-0 compatible, with a vendor name of Wrench. An SplClassLoader is bundled for convenience.
This creates a server on 127.0.0.1:8000 with one Application that listens for
WebSocket requests to
$server = new \Wrench\BasicServer('ws://localhost:8000', array( 'allowed_origins' => array( 'mysite.com', 'mysite.dev.localdomain' ) )); $server->registerApplication('echo', new \Wrench\Examples\EchoApplication()); $server->registerApplication('chat', new \My\ChatApplication()); $server->run();
The original maintainer and author was @nicokaiser. Plentiful improvements were contributed by @lemmingzshadow and @mazhack. Parts of the Socket class were written by Moritz Wutz. The server is licensed under the WTFPL, a free software compatible license.
- Add tests around fragmented payloads (split into many frames).
- To report issues, see the issue tracker.