PHPackages                             artisan-build/pusher-websocket-php - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. artisan-build/pusher-websocket-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

artisan-build/pusher-websocket-php
==================================

Pusher Channels websocket client library for PHP

v0.1.1(5mo ago)03221MITPHPPHP ^8.3CI passing

Since Jan 13Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/artisan-build/pusher-websocket-php)[ Packagist](https://packagist.org/packages/artisan-build/pusher-websocket-php)[ Docs](https://github.com/artisan-build/pusher-websocket-php)[ GitHub Sponsors](https://github.com/ArtisanBuild)[ RSS](/packages/artisan-build-pusher-websocket-php/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (13)Versions (3)Used By (1)

Pusher Channels WebSocket Client for PHP
========================================

[](#pusher-channels-websocket-client-for-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/76fc8aadfb4cd129a2eaec125503dcb9768062d16ad4cbe0580810bdd225f875/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6172746973616e2d6275696c642f7075736865722d776562736f636b65742d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/artisan-build/pusher-websocket-php)[![GitHub Tests Action Status](https://camo.githubusercontent.com/a5171ca8b9a942e4520aaf1d345031939238c476d2957141c5510889157f9f6a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6172746973616e2d6275696c642f7075736865722d776562736f636b65742d7068702f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/artisan-build/pusher-websocket-php/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/ca485477cf839ac4431bdbb6abbf801c9f6e2da1afc111b171fcae68c503e7e9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6172746973616e2d6275696c642f7075736865722d776562736f636b65742d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/artisan-build/pusher-websocket-php)

A PHP WebSocket client for Pusher Channels and Pusher-compatible servers. This is a port of [pusher-js](https://github.com/pusher/pusher-js) implementing Pusher Protocol v7.

When to Use This Package
------------------------

[](#when-to-use-this-package)

This package is a **low-level WebSocket client** for connecting to Pusher-compatible servers from PHP. It's designed for:

- CLI applications that need real-time communication
- Background workers or daemons
- Non-HTTP PHP processes that need WebSocket connections
- Building higher-level abstractions

**Laravel users:** You probably want [artisan-build/resonance](https://github.com/artisan-build/resonance) instead, which provides Laravel-specific integrations and brings this package as a dependency.

Requirements
------------

[](#requirements)

- PHP 8.3 or higher
- A Pusher-compatible WebSocket server:
    - [Pusher Channels](https://pusher.com/channels)
    - [Soketi](https://soketi.app)
    - [Laravel Reverb](https://reverb.laravel.com)

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

[](#installation)

```
composer require artisan-build/pusher-websocket-php
```

Usage
-----

[](#usage)

```
use ArtisanBuild\Pusher\Pusher;
use ArtisanBuild\Pusher\Options;

$pusher = new Pusher('your-app-key', new Options(
    cluster: 'mt1',
    wsHost: '127.0.0.1',
    wsPort: 6001,
    forceTLS: false,
));

// Subscribe to a channel
$channel = $pusher->subscribe('my-channel');

// Listen for events
$channel->bind('my-event', function ($data) {
    echo "Received: " . json_encode($data) . "\n";
});

// Connect to the server
$pusher->connect();
```

### Subscribing to Channels

[](#subscribing-to-channels)

```
// Public channel
$channel = $pusher->subscribe('news');

// Private channel (requires authentication)
$privateChannel = $pusher->subscribe('private-user-123');

// Presence channel (requires authentication)
$presenceChannel = $pusher->subscribe('presence-chat-room');
```

### Binding to Events

[](#binding-to-events)

```
// Bind to a specific event
$channel->bind('message', function ($data) {
    // Handle the event
});

// Bind to all events on a channel
$channel->bind_global(function ($event, $data) {
    echo "Event: {$event}\n";
});

// Unbind
$channel->unbind('message');
```

### Configuration Options

[](#configuration-options)

```
new Options(
    cluster: 'mt1',           // Pusher cluster (required for Pusher, empty for self-hosted)
    wsHost: '127.0.0.1',      // WebSocket host
    wsPort: 6001,             // WebSocket port (non-TLS)
    wssPort: 443,             // WebSocket port (TLS)
    forceTLS: true,           // Force TLS connection
    activityTimeout: 120000,  // Milliseconds before sending ping
    pongTimeout: 30000,       // Milliseconds to wait for pong
    channelAuthorization: [   // For private/presence channels
        'transport' => 'http',
        'endpoint' => 'https://your-app.com/broadcasting/auth',
        'headers' => [
            'Authorization' => 'Bearer your-token',
        ],
    ],
);
```

### Channel Authorization

[](#channel-authorization)

Private and presence channels require authorization. The `http` transport makes a POST request to your auth endpoint:

```
$pusher = new Pusher('app-key', new Options(
    wsHost: '127.0.0.1',
    wsPort: 8080,
    channelAuthorization: [
        'transport' => 'http',
        'endpoint' => 'https://your-app.com/broadcasting/auth',
        'headers' => [
            'Authorization' => 'Bearer ' . $token,
            'Accept' => 'application/json',
        ],
    ],
));

// Now private channels will authenticate automatically
$channel = $pusher->subscribe('private-user-123');
```

For custom authorization logic, use a `customHandler`:

```
channelAuthorization: [
    'customHandler' => function ($params, $callback) {
        // $params->socketId - the socket ID
        // $params->channelName - the channel being authorized

        // Make your own auth request...
        $authData = myCustomAuth($params);

        // Call back with result
        $callback(null, new ChannelAuthorizationData(auth: $authData['auth']));
    },
],
```

Development
-----------

[](#development)

### Prerequisites

[](#prerequisites)

You'll need a Pusher-compatible WebSocket server running locally for integration tests. Options include:

**Soketi** (recommended for development):

```
# Via npm (requires Node.js 14-18)
npx soketi start

# Via Docker
docker run -p 6001:6001 quay.io/soketi/soketi:1.6-16-debian
```

**Laravel Reverb** (if using Laravel Herd):

```
php artisan reverb:start
```

### Environment Setup

[](#environment-setup)

Copy the example environment file and configure your server:

```
cp .env.example .env
```

Edit `.env` with your server details:

```
PUSHER_HOST=127.0.0.1
PUSHER_PORT=6001
PUSHER_SCHEME=ws

PUSHER_APP_ID=app-id
PUSHER_APP_KEY=app-key
PUSHER_APP_SECRET=app-secret
PUSHER_CLUSTER=mt1
```

### Running Tests

[](#running-tests)

```
# Unit and feature tests (no server required)
composer test

# Integration tests (requires running server)
composer test:integration

# All tests
composer test:all

# With coverage
composer test:coverage

# Type coverage
composer test:types
```

### Code Quality

[](#code-quality)

```
# Linting
composer lint

# Static analysis
composer stan
```

Architecture
------------

[](#architecture)

This package is built on [ReactPHP](https://reactphp.org/) for asynchronous I/O:

- `ratchet/pawl` - WebSocket client
- `react/event-loop` - Event loop
- `react/promise` - Promises/async

The codebase follows the structure of pusher-js, ported to idiomatic PHP with full type coverage.

Contributing
------------

[](#contributing)

Contributions are welcome! Please ensure:

1. Tests pass: `composer test`
2. Code style is correct: `composer lint`
3. Static analysis passes: `composer stan`
4. Type coverage remains at 100%: `composer test:types`

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please report security vulnerabilities to .

Credits
-------

[](#credits)

- [Len Woodward](https://github.com/ProjektGopher)
- [Ed Grosvenor](https://github.com/edgrosvenor)
- [All Contributors](../../contributors)

This package is a PHP port of [pusher-js](https://github.com/pusher/pusher-js) by [Pusher](https://pusher.com).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance71

Regular maintenance activity

Popularity13

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

2

Last Release

166d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/63312522f1920cf5b3c34ea474511a484162b36166a33ae4b9fde6c65ab2c2fc?d=identicon)[ProjektGopher](/maintainers/ProjektGopher)

---

Top Contributors

[![ProjektGopher](https://avatars.githubusercontent.com/u/1688608?v=4)](https://github.com/ProjektGopher "ProjektGopher (53 commits)")

---

Tags

websocketpusherrealtime

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/artisan-build-pusher-websocket-php/health.svg)

```
[![Health](https://phpackages.com/badges/artisan-build-pusher-websocket-php/health.svg)](https://phpackages.com/packages/artisan-build-pusher-websocket-php)
```

###  Alternatives

[ccxt/ccxt

A cryptocurrency trading API with more than 100 exchanges in JavaScript / TypeScript / Python / C# / PHP / Go

43.2k341.0k1](/packages/ccxt-ccxt)[team-reflex/discord-php

An unofficial API to interact with the voice and text service Discord.

1.1k420.9k26](/packages/team-reflex-discord-php)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k106.6M349](/packages/pusher-pusher-php-server)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

136406.3k14](/packages/rector-rector-src)[centrifugal/phpcent

PHP library to communicate with Centrifugo HTTP API

1852.5M4](/packages/centrifugal-phpcent)[pusher/pusher-http-laravel

\[DEPRECATED\] A Pusher bridge for Laravel

404509.7k4](/packages/pusher-pusher-http-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
