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 today

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 1% of packages

Maintenance34

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://avatars.githubusercontent.com/u/48287550?v=4)[Iain Schmidt](/maintainers/primeapi)[@PrimeAPI](https://github.com/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

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M82](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M91](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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