PHPackages                             centrifugal/phpcent - 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. centrifugal/phpcent

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

centrifugal/phpcent
===================

PHP library to communicate with Centrifugo HTTP API

6.0.3(1mo ago)1852.5M↓23.4%37[1 issues](https://github.com/centrifugal/phpcent/issues)4MITPHPPHP &gt;=7.0.0CI passing

Since Jun 15Pushed 1mo ago5 watchersCompare

[ Source](https://github.com/centrifugal/phpcent)[ Packagist](https://packagist.org/packages/centrifugal/phpcent)[ Docs](https://github.com/centrifugal/phpcent)[ GitHub Sponsors](https://github.com/centrifugal)[ RSS](/packages/centrifugal-phpcent/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (2)Versions (27)Used By (4)

phpcent
=======

[](#phpcent)

[![Build Status](https://github.com/centrifugal/phpcent/workflows/test/badge.svg?branch=master)](https://github.com/centrifugal/phpcent/actions)[![Latest Version](https://camo.githubusercontent.com/3605fe4d9a8b32914ba003c21ff18bbd8b72132c974c6e30845c11cf5557fc03/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f63656e747269667567616c2f70687063656e742e7376673f7374796c653d666c61742d737175617265)](https://github.com/centrifugal/phpcent/releases)

PHP library to communicate with Centrifugo v5 HTTP API (for Centrifugo v4 use phpcent v5.x, for Centrifugo v3 use phpcent v4.x).

Library is published on the Composer:

```
composer require centrifugal/phpcent:~6.0
```

See [Centrifugo server API documentation](https://centrifugal.dev/docs/server/server_api).

Basic Usage:

```
$client = new \phpcent\Client("http://localhost:8000/api");
$client->setApiKey("Centrifugo API key");
$client->publish("channel", ["message" => "Hello World"]);
```

You can use `phpcent` to create connection token (JWT):

```
$token = $client->setSecret("Centrifugo secret key")->generateConnectionToken($userId);
```

Connection token that will be valid for 5 minutes:

```
$token = $client->setSecret("Centrifugo secret key")->generateConnectionToken($userId, time() + 5*60);
```

It's also possible to generate channel subscription token:

```
$token = $client->setSecret("Centrifugo secret key")->generateSubscriptionToken($userId, $channel);
```

It's also possible to generate channel subscription token with expiration time, for example token for 30 mins:

```
$token = $client->setSecret("Centrifugo secret key")->generateSubscriptionToken($userId, $channel, time() + 30*60);
```

Also API key and secret can be set in constructor:

```
$client = new \phpcent\Client("http://localhost:8000/api", "", "");
```

Timeouts:

```
$client->setConnectTimeoutOption(0); // Seconds | 0 = never
$client->setTimeoutOption(2); // Seconds
```

All available API methods:

```
$response = $client->publish($channel, $data);
$response = $client->broadcast($channels, $data);
$response = $client->subscribe($channel, $userId);
$response = $client->unsubscribe($channel, $userId);
$response = $client->disconnect($userId);
$response = $client->presence($channel);
$response = $client->presenceStats($channel);
$response = $client->history($channel);
$response = $client->historyRemove($channel);
$response = $client->channels();
$response = $client->info();
$response = $client->batch($data);
```

To use `assoc` option while decoding JSON in response:

```
$client->setUseAssoc(true);
```

### SSL

[](#ssl)

In case if your Centrifugo server has invalid SSL certificate, you can use:

```
$client->setSafety(false);
```

You can also use self signed certificate in safe manner:

```
$client = new \phpcent\Client("https://localhost:8000/api");
$client->setCert("/path/to/certificate.pem");
$client->setCAPath("/ca/path"); // if you need.
```

*Note:* Certificate must match with host name in `Client` address (`localhost` in example above).

### DNS Resolution

[](#dns-resolution)

This error may indicate your system is having trouble resolving IPv6 addresses:

```
cURL error: Resolving timed out after [value] milliseconds

```

By default, both IPv4 and IPv6 addresses will attempt to be resolved. You can force it to only resolve IPv4 addresses with:

```
$client->forceIpResolveV4();
```

### Testing

[](#testing)

Requirements:

- git
- A supported version of PHP
- [composer](http://getcomposer.org/download)
- [Docker](https://www.docker.com/products/docker-desktop)

The provided PHPUnit tests assume that a local [Centrifugo](https://github.com/centrifugal/centrifugo) server is running and available at port 8000. This can be accomplished using Docker and the [official Centrifugo image](https://hub.docker.com/r/centrifugo/centrifugo/).

```
# Install package dependencies.
$ composer install

# The following command starts a Centrifugo server running in a background Docker container.
$ docker run -d -p 8000:8000 --name centrifugo centrifugo/centrifugo centrifugo --api_insecure

# Run the test suite.
$ vendor/bin/phpunit

# Shut down the Centrifugo container.
$ docker stop centrifugo
```

Authors
=======

[](#authors)

- [Dmitriy Soldatenko](https://github.com/sl4mmer)
- [Dmitriy Tetekin](https://github.com/Tomchanskiy)

###  Health Score

65

—

FairBetter than 99% of packages

Maintenance89

Actively maintained with recent releases

Popularity59

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 50% 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 ~199 days

Recently: every ~285 days

Total

21

Last Release

56d ago

Major Versions

1.0.5 → v2.x-dev2018-12-05

2.2.0 → 3.0.02019-05-14

3.1.1 → 4.0.02021-09-06

4.0.0 → 5.0.02022-09-29

5.1.0 → 6.0.02024-06-20

PHP version history (3 changes)0.5.0PHP &gt;=5.3.0

3.0.2PHP &gt;=5.4.0

4.0.0PHP &gt;=7.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9273a44311a83affa2bee70b36f618b27a251ed0bb8c1cf2551655122a9e1a34?d=identicon)[FZambia](/maintainers/FZambia)

---

Top Contributors

[![FZambia](https://avatars.githubusercontent.com/u/1196565?v=4)](https://github.com/FZambia "FZambia (50 commits)")[![sl4mmer](https://avatars.githubusercontent.com/u/1143307?v=4)](https://github.com/sl4mmer "sl4mmer (30 commits)")[![khvalov](https://avatars.githubusercontent.com/u/2668527?v=4)](https://github.com/khvalov "khvalov (2 commits)")[![Vovan-VE](https://avatars.githubusercontent.com/u/1166581?v=4)](https://github.com/Vovan-VE "Vovan-VE (2 commits)")[![jumper572](https://avatars.githubusercontent.com/u/29145733?v=4)](https://github.com/jumper572 "jumper572 (2 commits)")[![beporter](https://avatars.githubusercontent.com/u/637270?v=4)](https://github.com/beporter "beporter (2 commits)")[![SteveTherrien](https://avatars.githubusercontent.com/u/9618303?v=4)](https://github.com/SteveTherrien "SteveTherrien (2 commits)")[![Tomchanskiy](https://avatars.githubusercontent.com/u/34372563?v=4)](https://github.com/Tomchanskiy "Tomchanskiy (1 commits)")[![xAockd](https://avatars.githubusercontent.com/u/3390348?v=4)](https://github.com/xAockd "xAockd (1 commits)")[![aleksraiden](https://avatars.githubusercontent.com/u/65920?v=4)](https://github.com/aleksraiden "aleksraiden (1 commits)")[![yagobski](https://avatars.githubusercontent.com/u/220980?v=4)](https://github.com/yagobski "yagobski (1 commits)")[![AntistressStore](https://avatars.githubusercontent.com/u/80528523?v=4)](https://github.com/AntistressStore "AntistressStore (1 commits)")[![BaBL86](https://avatars.githubusercontent.com/u/483972?v=4)](https://github.com/BaBL86 "BaBL86 (1 commits)")[![Darkkin](https://avatars.githubusercontent.com/u/8968720?v=4)](https://github.com/Darkkin "Darkkin (1 commits)")[![everlCode](https://avatars.githubusercontent.com/u/82755522?v=4)](https://github.com/everlCode "everlCode (1 commits)")[![hetao29](https://avatars.githubusercontent.com/u/8010298?v=4)](https://github.com/hetao29 "hetao29 (1 commits)")[![juliustm](https://avatars.githubusercontent.com/u/3254503?v=4)](https://github.com/juliustm "juliustm (1 commits)")

---

Tags

websocketmessagingrealtimecentrifugo

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/centrifugal-phpcent/health.svg)

```
[![Health](https://phpackages.com/badges/centrifugal-phpcent/health.svg)](https://phpackages.com/packages/centrifugal-phpcent)
```

###  Alternatives

[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k106.6M350](/packages/pusher-pusher-php-server)[sl4mmer/phpcent

PHP library to communicate with Centrifugo HTTP API

185296.5k1](/packages/sl4mmer-phpcent)[denis660/laravel-centrifugo

Centrifugo broadcaster for laravel

121190.2k](/packages/denis660-laravel-centrifugo)[basement-chat/basement-chat

Add a real-time chat widget to your Laravel application.

4984.0k](/packages/basement-chat-basement-chat)[vinelab/minion

A Simple WAMP (Web Application Messaging Protocol) server and command line tool

1276.5k](/packages/vinelab-minion)[takielias/codeigniter-websocket

CodeIgniter Websocket using Ratchet Websocket technology. Inspired by https://github.com/romainrg/ratchet\_client

639.4k](/packages/takielias-codeigniter-websocket)

PHPackages © 2026

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