Download the PHP package brash/websocket-middleware without Composer

On this page you can find all versions of the php package brash/websocket-middleware. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package websocket-middleware

WebSocket PHP


WebSocket Middleware for react/http

This package provides a PHP React/HTTP WebSocket Middleware.

Requires PHP 8.3+

This library provides a WebSocket message broadcasting solution using the ReactPHP library. It demonstrates how to handle incoming text messages, broadcast messages to other connected clients, and log connection details.

Requirements

Installation

  1. Install the dependencies via Composer:

  2. Ensure the autoloader is included:

Usage

Starting the Server

Run the WebSocket server by executing the script in your terminal:

Key Components

AbstractTextMessageHandler

The AbstractTextMessageHandler class handles WebSocket text messages. This implementation processes new connections, receives data, and broadcasts it to other connected clients.

MiddlewareFactory

Creates the middleware required for handling WebSocket connections.

React\Http\HttpServer

Handles HTTP requests and integrates WebSocket middleware.

Implementation Details

  1. Connection Handling

    • The server tracks all active connections in the $connections array.
    • When a new connection is established, it is added to the array using the onOpen method.
  2. Message Broadcasting
    • When a client sends a message, it is logged using the connection’s logger.
    • The message is broadcast to all other clients, except the sender.
    • The sender receives a response that includes their IP address and the message content in uppercase.

Code Example

Here is the core server implementation:

Example Output

When a client connects and sends a message:

  1. The server logs the IP address and message data.
  2. All other connected clients receive the message.
  3. The sender receives a response in uppercase:

Config Options

It is optional to set a Config object in the MiddlewareFactory, but you can do it as:

It is optional to set an array of paths, but this can be achieved as follows:

License

This library is licensed under the MIT License. See the LICENSE file for more details.

Contributions

Contributions are welcome! Feel free to submit issues or pull requests on GitHub.

Acknowledgments


Enjoy using the WebSocket Message Broadcasting Library!


All versions of websocket-middleware with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3.0
brash/websocket Version ^1.0
monolog/monolog Version ^3.8
psr/http-message Version ~1.1|^2.0
react/http Version ^1.11
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package brash/websocket-middleware contains the following files

Loading the files please wait ....