PHPackages                             basanta/laravel-websocket - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. basanta/laravel-websocket

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

basanta/laravel-websocket
=========================

WebSocket server for Laravel applications

02JavaScript

Since Jul 16Pushed 9mo agoCompare

[ Source](https://github.com/basantashubhu/laravel-websocket)[ Packagist](https://packagist.org/packages/basanta/laravel-websocket)[ RSS](/packages/basanta-laravel-websocket/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel WebSocket
=================

[](#laravel-websocket)

A simple and lightweight WebSocket server package for Laravel applications that enables real-time event broadcasting.

Features
--------

[](#features)

- 🚀 **Lightweight WebSocket Server**: Pure Node.js WebSocket implementation without external dependencies
- 🔄 **Real-time Event Broadcasting**: Automatic broadcasting of Laravel events to connected WebSocket clients
- 🎯 **Event-driven Architecture**: Listen to all Laravel events and broadcast specific ones
- 📡 **HTTP API**: RESTful endpoints for manual event emission and server monitoring
- 🔌 **Simple Integration**: Easy setup with Laravel service provider
- ⚡ **High Performance**: Minimal overhead with efficient message handling
- ⚙️ **Configurable Port**: Support for custom port configuration via command-line arguments
- 📊 **Server Monitoring**: Built-in status endpoint to monitor connected clients
- 🎮 **Testing Playground**: Built-in web interface for testing WebSocket connections

Installation
------------

[](#installation)

### 1. Install the Package

[](#1-install-the-package)

```
composer require basanta/laravel-websocket
```

### 2. Register the Service Provider (Optional)

[](#2-register-the-service-provider-optional)

**For Laravel 5.5+**: The package will be auto-discovered automatically. No manual registration required.

**For older Laravel versions**: Add the service provider to your `config/app.php`:

```
'providers' => [
    // Other service providers...
    Basanta\LaravelWebsocket\LaravelWebsocketProvider::class,
],
```

### 3. Publish Configuration (Optional)

[](#3-publish-configuration-optional)

Publish the configuration file to customize settings:

```
php artisan vendor:publish --tag=websocket-config
```

This will create a `config/websocket.php` file where you can customize:

- WebSocket server port
- Host address
- Connection timeout
- Debug logging

### 4. Install Node.js Dependencies

[](#4-install-nodejs-dependencies)

The WebSocket server requires Guzzle HTTP client for communication:

```
composer require guzzlehttp/guzzle
```

### 5. Start the WebSocket Server

[](#5-start-the-websocket-server)

#### Option 1: Using Laravel Command (Recommended)

[](#option-1-using-laravel-command-recommended)

```
php artisan websocket:serve
```

#### Option 2: Manual Start

[](#option-2-manual-start)

Navigate to the package directory and start the Node.js server:

```
cd vendor/basanta/laravel-websocket/server
node app.js
```

Or copy the `server/app.js` file to your project root and run:

```
node app.js
```

The server will start on `ws://localhost:6001` by default.

#### Quick Test

[](#quick-test)

Once the server is running, you can test it immediately by visiting the built-in playground:

```
http://your-app.test/laravel-websocket/playground

```

#### Custom Port Configuration

[](#custom-port-configuration)

You can specify a custom port using command-line arguments:

```
# Run on port 3000
node app.js --port=3000

# Run on port 9000
node app.js --port=9000
```

Usage
-----

[](#usage)

### Basic Event Broadcasting

[](#basic-event-broadcasting)

To broadcast an event via WebSocket, implement the `ShouldBroadcastWebsocket` contract in your event class:

```
