Download the PHP package socket-bridge/laravel-socketio without Composer

On this page you can find all versions of the php package socket-bridge/laravel-socketio. 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 laravel-socketio

Laravel Socket.IO Bridge

Reusable Laravel integration for authenticated Socket.IO events transported through Redis.

The package contains the Laravel integration layer. The companion Socket.IO gateway is included in the node/ directory and runs as a separate Node.js service.

Quick start

Run these steps in order:

Then:

  1. Add the Redis settings shown below to .env.
  2. Register testEvent in AppServiceProvider.
  3. Start Redis and Laravel.
  4. Start the gateway with php artisan socket-bridge:install --start.
  5. Connect a Socket.IO client with a valid access token.

socket-bridge:install only checks Node.js/npm and installs dependencies. The --start option runs the gateway in the current terminal. For production, use Supervisor so it starts and restarts automatically.

Requirements

Installation

Install the package with Composer:

Publish the package configuration:

The package service provider is registered automatically through Laravel package discovery.

After installation, use the package command to verify Node.js and npm and install the gateway dependencies:

If Node.js or npm is not installed, the command stops and asks you to install Node.js 20 or newer before running it again. To install the dependencies and run the gateway in the foreground:

For production, run the install command without --start, then use the Supervisor configuration below so the gateway is monitored and restarted automatically.

Available Artisan commands

Command Purpose
php artisan socket-bridge:install Checks Node.js/npm and installs the gateway dependencies.
php artisan socket-bridge:install --start Installs dependencies and starts the gateway in the foreground.

There is currently no php artisan socket-bridge:test command. Testing is done by registering the testEvent example below, starting Redis, Laravel, and the gateway, and then emitting testEvent from a Socket.IO client.

Updating the package

For an existing Laravel application, update the package with Composer:

After updating, run the installer again so the gateway dependencies match the package version:

If the published configuration file has changed, republish it after reviewing your local settings:

Restart the gateway after an update. If Supervisor manages it:

Commit composer.lock in the Laravel application when using a locked deployment workflow.

Configuration

The published configuration file is:

Redis settings can be configured through environment variables:

If SOCKET_BRIDGE_REDIS_URL is not set, the package falls back to REDIS_URL and then to the default Redis URL defined in the configuration file.

Registering an event

The package automatically discovers listener classes in app/Listeners whose names start with HandleSocket.

For example, create app/Listeners/HandleSocketTestEvent.php:

The prefix is removed and the first remaining character is converted to lowercase:

Listeners are resolved through Laravel's service container, so constructor dependencies are supported. The handle() method receives the payload and authenticated user ID.

Manual registration is also supported through SocketEventRegistry:

The application remains responsible for authorization, payload validation, and business logic.

Test event

The quickest test is to create app/Listeners/HandleSocketTestEvent.php using the example above. After Laravel starts, the listener is discovered automatically. Emit testEvent from the Socket.IO client shown below.

Manual registration remains available when you need a custom event name or closure:

From a Socket.IO client, emit the event after connecting with a valid access token:

The handler receives the event payload and authenticated user ID. Return an array to send a response to the client. Add authorization and payload validation inside the handler or in your application's existing authorization layer.

You do not need php artisan make:event or php artisan make:listener; those commands create Laravel event/listener classes and are not used for socket listener discovery.

Automatic discovery runs when Laravel boots. Restart Laravel and the gateway after adding a new listener while the application is running.

Test the event

Run the following in separate terminals:

Then connect a Socket.IO client with a valid access token and emit testEvent. A successful test returns the message, user_id, and payload from the PHP handler. If the test fails, check the access token, Redis URL, matching channel names, gateway port, and CORS origin.

Server setup

The bridge requires Redis, the Laravel application, and the Node.js Socket.IO gateway:

  1. Start Redis.
  2. Install and configure the Laravel package.
  3. Start the Socket.IO gateway from the package's node/ directory.

Example local setup:

The gateway listens on port 6006 by default. Configure the connection with:

The Laravel and gateway Redis channel settings must match. If you change the Laravel SOCKET_BRIDGE_*_CHANNEL values, set the corresponding variables for the Node.js gateway too.

Run the gateway automatically

For production, use a process manager so the gateway starts on boot and restarts if it exits. For example, install Supervisor and create /etc/supervisor/conf.d/socket-bridge-gateway.conf:

Replace /var/www/your-app, www-data, the Redis URL, and the allowed origin with your deployment values. Then enable the service:

Useful management commands:

Do not start the gateway from a Laravel service provider or an HTTP request. It is a long-running service and should be monitored independently from PHP.

Troubleshooting

License

This package is released under the MIT license.


All versions of laravel-socketio with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
illuminate/console Version >=10.0
illuminate/contracts Version >=10.0
illuminate/support Version >=10.0
predis/predis Version >=2.0
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 socket-bridge/laravel-socketio contains the following files

Loading the files please wait ...