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
==================================

1.0.0(1y ago)518.7k↓28.7%22MITPHPCI passing

Since May 10Pushed 2mo 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 3d ago

READMEChangelog (4)Dependencies (4)Versions (5)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

42

—

FairBetter than 88% of packages

Maintenance67

Regular maintenance activity

Popularity33

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity44

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

Total

4

Last Release

465d ago

Major Versions

0.3.0 → 1.0.02025-03-27

### 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

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[illuminate/http

The Illuminate Http package.

11937.9M7.0k](/packages/illuminate-http)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)[guzzlehttp/test-server

Node.js server and PHP controller

14284.0k22](/packages/guzzlehttp-test-server)

PHPackages © 2026

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