PHPackages                             primeapi/websocket-client - 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. primeapi/websocket-client

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

primeapi/websocket-client
=========================

PHP WebSocket Client Example for PrimeAPI.io

00PHP

Since Apr 23Pushed 1y agoCompare

[ Source](https://github.com/PrimeAPI-io/primeapi-websocket-client-php)[ Packagist](https://packagist.org/packages/primeapi/websocket-client)[ RSS](/packages/primeapi-websocket-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PrimeAPI.io PHP WebSocket Client
================================

[](#primeapiio-php-websocket-client)

This repository contains a reference implementation of a WebSocket client for the PrimeAPI.io streaming FX data service.

It also contains a basic CLI demo script.

Get An API Key
--------------

[](#get-an-api-key)

If you don't already have an API key, you can get one by signing up for free at

Installing the Client in your Application
-----------------------------------------

[](#installing-the-client-in-your-application)

```
composer install primeapi/php-websocket-client
```

### Using the Client

[](#using-the-client)

You're going to need a Price Handler - a class that implements the `PriceHandlerInterface` interface. This is where you will handle the incoming price data from the WebSocket server.

Here's a simple anonymous class implementation that just echos out the prices.

```
$priceHandler = new class implements \PrimeAPI\WebSocket\PriceHandlerInterface {
    public function price(string $symbol, ?string $bid, ?string $ask): void
    {
        echo sprintf("Price for %s: Bid: %s, Ask: %s", $symbol, $bid, $ask), PHP_EOL;
    }
};
```

Creating and starting a WebSocket client is super simple.

```
$primeClient = new \PrimeAPI\WebSocket\Client();
    ->apiKey('your-api-key');
    ->realTimePairs(['USDJPY', 'AUDCAD']);
    ->priceHandler($priceHandler);
    ->start();
```

Running as a Demo
-----------------

[](#running-as-a-demo)

The client contains a demo script that can be run to test the connection to the PrimeAPI.io WebSocket server.

You can install and run locally, or use our pre built Docker image.

### CLI arguments

[](#cli-arguments)

- `--key=your-api-key` - Your PrimeAPI.io API key
- `--pairs=EURUSD,GBPUSD` - A comma separated list of currency pairs to subscribe to (default: `EURUSD`)
- `--prices` - Only show price bid/ask outputs
- `--debug` - (default) Show all WebSocket messages, including connect, auth, prices etc.

### Run The Demo With Docker

[](#run-the-demo-with-docker)

```
docker run --rm -e PRIME_API_KEY=your_api_key primeimg/php-websocket-client:latest
```

Or, if you want to provide arguments

```
docker run --rm primeimg/php-websocket-client:latest php /app/bin/demo.php --key=your_api_key --pairs=EURUSD,GBPUSD
```

### Install &amp; Run Demo Locally

[](#install--run-demo-locally)

```
composer install
```

```
export PRIME_API_KEY=your_api_key
```

```
php bin/demo.php
```

And with arguments

```
php bin/demo.php --key=your_api_key --pairs=EURUSD,GBPUSD
```

### Expected CLI Demo Output

[](#expected-cli-demo-output)

```
Got message: {"op":"connect","status":200,"tsp":1744914599148,"msg":"Connected to ws-grp-prime-euc2-hjf5"}
Got message: {"op":"auth","status":200,"tsp":1744914599299,"msg":"Authenticated OK"}
Got message: {"op":"subscribe","status":200,"tsp":1744914599389,"msg":"Subscribed to 1 channel"}
Got message: {"op":"price","sym":"EURUSD","bid":"1.13575","ask":"1.13577"}
Got message: {"op":"price","sym":"EURUSD","bid":"1.1357","ask":"1.1358"}
Got message: {"op":"price","sym":"EURUSD","bid":"1.13569","ask":"1.1358"}
Got message: {"op":"price","sym":"EURUSD","bid":"1.13574","ask":"1.13575"}

```

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity15

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/63f32d3ba20309bca3ffa84759067c0c11ee1806a54dbb31853a7c61e7bb6bfa?d=identicon)[primeapi](/maintainers/primeapi)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/primeapi-websocket-client/health.svg)

```
[![Health](https://phpackages.com/badges/primeapi-websocket-client/health.svg)](https://phpackages.com/packages/primeapi-websocket-client)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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