PHPackages                             valtzu/guzzle-websocket-middleware - 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. valtzu/guzzle-websocket-middleware

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

valtzu/guzzle-websocket-middleware
==================================

0.3.0(1y ago)515.6k↓11.3%22MITPHPCI passing

Since May 10Pushed 1y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (2)Versions (4)Used By (2)

Connect to WebSocket endpoints with Guzzle HTTP client
------------------------------------------------------

[](#connect-to-websocket-endpoints-with-guzzle-http-client)

**NOTE:** Only `StreamHandler` supported (so not `CurlHandler`!).

### Installation

[](#installation)

```
composer require valtzu/guzzle-websocket-middleware

```

### Usage

[](#usage)

Guzzle's `synchronous` option is used to configure the stream blocking option.

#### Synchronous usage

[](#synchronous-usage)

```
$handlerStack = new HandlerStack(new StreamHandler());
$handlerStack->unshift(new WebSocketMiddleware());

$guzzle = new Client(['handler' => $handlerStack]);

$handshakeResponse = $guzzle->request('GET', 'wss://ws.postman-echo.com/raw');
$ws = $handshakeResponse->getBody();

$ws->write("Hello world");
$helloWorld = $ws->read(); // This will block until the reply frame is received
```

#### Asynchronous usage

[](#asynchronous-usage)

```
$handlerStack = new HandlerStack(new StreamHandler());
$handlerStack->unshift(new WebSocketMiddleware());

$guzzle = new Client(['handler' => $handlerStack]);

$handshakeResponse = $guzzle->requestAsync('GET', 'wss://ws.postman-echo.com/raw')->wait();
$ws = $handshakeResponse->getBody();

$ws->write("Hello world");
$helloWorld = $ws->read(); // Here you may get an empty string if data wasn't received yet
```

#### Connection upkeep / ping-pong

[](#connection-upkeep--ping-pong)

Whenever you read from a websocket stream, instead of receiving a text/binary frame, you may receive "ping" instead. When this happens, we automatically respond with "pong". However, due to being PHP (usually) being single-threaded, this means that you must make sure `read` (even with `0` length) is done frequently enough.

It's also possible to manually send a ping – however, it does not wait for the other party to reply.

```
$ws->ping();
```

### Contributing

[](#contributing)

1. If you have an issue with package, or you have a feature request, please open an issue
2. If you want to contribute code, you may submit a Pull Request. Just remember to add tests.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance43

Moderate activity, may be stable

Popularity32

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 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 ~115 days

Total

3

Last Release

507d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/27bf615bb0a15c8a9eea4b1d8159ed55efc07ec17e31c426d878f9454f535772?d=identicon)[valtzu](/maintainers/valtzu)

---

Top Contributors

[![valtzu](https://avatars.githubusercontent.com/u/652734?v=4)](https://github.com/valtzu "valtzu (12 commits)")

---

Tags

guzzleguzzle-middlewarephp8websocketwswss

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/valtzu-guzzle-websocket-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/valtzu-guzzle-websocket-middleware/health.svg)](https://phpackages.com/packages/valtzu-guzzle-websocket-middleware)
```

###  Alternatives

[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[omniphx/forrest

A Laravel library for Salesforce

2724.4M8](/packages/omniphx-forrest)[akamai-open/edgegrid-client

Implements the Akamai {OPEN} EdgeGrid Authentication specified by https://developer.akamai.com/introduction/Client\_Auth.html

482.5M6](/packages/akamai-open-edgegrid-client)[muhammadhuzaifa/telescope-guzzle-watcher

Telescope Guzzle Watcher provide a custom watcher for intercepting http requests made via guzzlehttp/guzzle php library. The package uses the on\_stats request option for extracting the request/response data. The watcher intercept and log the request into the Laravel Telescope HTTP Client Watcher.

98239.8k1](/packages/muhammadhuzaifa-telescope-guzzle-watcher)[onesignal/onesignal-php-api

A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com

34170.2k2](/packages/onesignal-onesignal-php-api)[ory/hydra-client-php

Documentation for all of Ory Hydra's APIs.

1710.8k](/packages/ory-hydra-client-php)

PHPackages © 2026

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