PHPackages                             hetao29/phpcent2 - 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. hetao29/phpcent2

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

hetao29/phpcent2
================

PHP library to communicate with Centrifugo HTTP API

2.0.1(7y ago)03.1kMITPHPPHP &gt;=5.3.0

Since Nov 1Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/hetao29/phpcent2)[ Packagist](https://packagist.org/packages/hetao29/phpcent2)[ Docs](https://github.com/centrifugal/phpcent)[ RSS](/packages/hetao29-phpcent2/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

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->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();
```

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

39

—

LowBetter than 86% of packages

Maintenance58

Moderate activity, may be stable

Popularity16

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Unknown

Total

1

Last Release

2752d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b835c445e79339f6c8401b78b03cc22776c850189c94fddb93fa685d7986a168?d=identicon)[hetao29](/maintainers/hetao29)

---

Top Contributors

[![FZambia](https://avatars.githubusercontent.com/u/1196565?v=4)](https://github.com/FZambia "FZambia (47 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

centrifugo

### Embed Badge

![Health badge](/badges/hetao29-phpcent2/health.svg)

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

###  Alternatives

[shopify/shopify-api

Shopify API Library for PHP

4634.8M16](/packages/shopify-shopify-api)[omniphx/forrest

A Laravel library for Salesforce

2724.4M8](/packages/omniphx-forrest)[centrifugal/phpcent

PHP library to communicate with Centrifugo HTTP API

1822.3M4](/packages/centrifugal-phpcent)[xeroapi/xero-php-oauth2

Xero official PHP SDK for oAuth2 generated with OpenAPI spec 3

1054.3M14](/packages/xeroapi-xero-php-oauth2)[vgrem/php-spo

PHP Office 365 library. It allows to performs CRUD operations against Office 365 resources via an REST/OData based API

3741.4M5](/packages/vgrem-php-spo)[bigcommerce/api

Enables PHP applications to communicate with the Bigcommerce API.

1501.1M8](/packages/bigcommerce-api)

PHPackages © 2026

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