PHPackages                             pubnub/pubnub - 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. [API Development](/categories/api)
4. /
5. pubnub/pubnub

ActiveLibrary[API Development](/categories/api)

pubnub/pubnub
=============

This is the official PubNub PHP SDK repository.

9.0.0(6mo ago)1314.6M—4.3%89[2 issues](https://github.com/pubnub/php/issues)[8 PRs](https://github.com/pubnub/php/pulls)17proprietaryPHPPHP &gt;=8.1CI passing

Since Jun 14Pushed 3mo ago39 watchersCompare

[ Source](https://github.com/pubnub/php)[ Packagist](https://packagist.org/packages/pubnub/pubnub)[ Docs](http://www.pubnub.com/)[ RSS](/packages/pubnub-pubnub/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (80)Used By (17)Security (1)

PubNub PHP SDK (V4)
===================

[](#pubnub-php-sdk-v4)

[![Build Status](https://camo.githubusercontent.com/de056d2f21e1f1f5587cc7e22d042ab6cf7cb3bc33af82de6cb1aceb4be33abb/68747470733a2f2f7472617669732d63692e636f6d2f7075626e75622f7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/pubnub/php)[![codecov](https://camo.githubusercontent.com/a0309c518829ac3ddebca93c202c9c2e1e1c5c26deaf9abd65076274c6795f1c/68747470733a2f2f636f6465636f762e696f2f67682f7075626e75622f7068702f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/pubnub/php)[![Docs](https://camo.githubusercontent.com/5b71c5998edb2f63cb60d78c7fa31f7bafe770d91f82a392043e4141899264e1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63732d6f6e6c696e652d626c75652e737667)](https://www.pubnub.com/docs/php/pubnub-php-sdk)[![GitHub release (latest by date)](https://camo.githubusercontent.com/10855ddddb22e84aeb41f81e3b7e168c08bb51c75ae2250c2cbdba104e7289dd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f7075626e75622f706870)](https://camo.githubusercontent.com/10855ddddb22e84aeb41f81e3b7e168c08bb51c75ae2250c2cbdba104e7289dd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f7075626e75622f706870)

This is the official PubNub PHP SDK repository.

PubNub takes care of the infrastructure and APIs needed for the realtime communication layer of your application. Work on your app's logic and let PubNub handle sending and receiving data across the world in less than 100ms.

The SDK supports PHP 7.4 and 8.x.

Get keys
--------

[](#get-keys)

You will need the publish and subscribe keys to authenticate your app. Get your keys from the [Admin Portal](https://dashboard.pubnub.com/login).

Configure PubNub
----------------

[](#configure-pubnub)

1. Integrate the PHP SDK into your project:

    - Without composer

        1. Clone the following repository: `git clone https://github.com/pubnub/php.git ./pubnub-php`
        2. Copy the `src` folder to your project.
        3. Include `autoloader.php` file in your project:

            ```
            require_once('src/autoloader.php');
            ```
        4. Download dependency `monolog` from  and copy the `monolog` folder from the `src` folder to the `src` folder of your project.
        5. Download dependency `psr/Log` from  and copy the `psr` folder to the `src` folder of your project.
        6. Download dependency `rmccue` from  and copy the `Requests` folder and the file `Requests.php` from the `library` folder to the `src` folder of your project.
    - With composer

        1. Add the PubNub package to your `composer.json` file:

            ```
            {
                "require": {

                    "pubnub/pubnub": "9.0.0"
                }
            }
            ```
        2. Run `composer install --no-dev‌` from the command line. This installs the PubNub PHP SDK and all its dependencies in the `vendor` folder of the project.
        3. Include `autoload.php` file in your project:

            ```
            require_once('vendor/autoload.php');‌
            ```
2. Configure your keys:

    ```
    $pnconf = new PNConfiguration();
    $pubnub = new PubNub($pnconf);

    $pnconf->setSubscribeKey("mySubscribeKey");
    $pnconf->setPublishKey("myPublishKey");
    $pnconf->setUserId("ReplaceWithYourClientIdentifier");
    ```

Add event listeners
-------------------

[](#add-event-listeners)

```
class MySubscribeCallback extends SubscribeCallback {
    function status($pubnub, $status) {
        if ($status->getCategory() === PNStatusCategory::PNUnexpectedDisconnectCategory) {
        // This event happens when radio / connectivity is lost
        } else if ($status->getCategory() === PNStatusCategory::PNConnectedCategory){
        // Connect event. You can do stuff like publish, and know you'll get it // Or just use the connected event to confirm you are subscribed for // UI / internal notifications, etc
        } else if ($status->getCategory() === PNStatusCategory::PNDecryptionErrorCategory){
        // Handle message decryption error. Probably client configured to // encrypt messages and on live data feed it received plain text.
        }
    }
    function message($pubnub, $message){
    // Handle new message stored in message.message
    }
    function presence($pubnub, $presence){
    // handle incoming presence data
    }
}

$subscribeCallback = new MySubscribeCallback();
$pubnub->addListener($subscribeCallback);
```

Publish/subscribe
-----------------

[](#publishsubscribe)

```
$pubnub->subscribe()
    ->channels("hello_world")
    ->execute();

$pubnub->publish()
    ->channel("hello_world")
    ->message("Hello PubNub!")
    ->sync();
```

Documentation
-------------

[](#documentation)

- [API reference for PHP ](https://www.pubnub.com/docs/sdks/php)

Support
-------

[](#support)

If you **need help** or have a **general question**, contact .

###  Health Score

69

—

FairBetter than 100% of packages

Maintenance73

Regular maintenance activity

Popularity62

Solid adoption and visibility

Community40

Growing community involvement

Maturity87

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 80.2% 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 ~68 days

Total

62

Last Release

201d ago

Major Versions

4.7.0 → 5.0.02022-01-26

5.1.0 → 6.0.02023-02-01

6.3.0 → 7.0.02024-06-27

7.4.0 → 8.0.02025-03-19

8.0.2 → 9.0.02025-10-30

PHP version history (5 changes)3.5PHP &gt;=5.3.0

4.0.0-alphaPHP &gt;=5.6.0

6.0.0PHP ^7.4|&gt;=8.0

7.1.0PHP &gt;=8.0

8.0.0PHP &gt;=8.1

### Community

Maintainers

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

---

Top Contributors

[![anovikov1984](https://avatars.githubusercontent.com/u/6103830?v=4)](https://github.com/anovikov1984 "anovikov1984 (292 commits)")[![qsoftdevelopment](https://avatars.githubusercontent.com/u/1560280?v=4)](https://github.com/qsoftdevelopment "qsoftdevelopment (20 commits)")[![client-engineering-bot](https://avatars.githubusercontent.com/u/60980775?v=4)](https://github.com/client-engineering-bot "client-engineering-bot (11 commits)")[![qsdstefan](https://avatars.githubusercontent.com/u/41143293?v=4)](https://github.com/qsdstefan "qsdstefan (10 commits)")[![parfeon](https://avatars.githubusercontent.com/u/794617?v=4)](https://github.com/parfeon "parfeon (7 commits)")[![crimsonred](https://avatars.githubusercontent.com/u/2394089?v=4)](https://github.com/crimsonred "crimsonred (4 commits)")[![MaxPresman](https://avatars.githubusercontent.com/u/45400?v=4)](https://github.com/MaxPresman "MaxPresman (3 commits)")[![marcin-cebo](https://avatars.githubusercontent.com/u/102806110?v=4)](https://github.com/marcin-cebo "marcin-cebo (3 commits)")[![stephenlb](https://avatars.githubusercontent.com/u/45214?v=4)](https://github.com/stephenlb "stephenlb (3 commits)")[![frederickbrock](https://avatars.githubusercontent.com/u/49744?v=4)](https://github.com/frederickbrock "frederickbrock (2 commits)")[![techwritermat](https://avatars.githubusercontent.com/u/39187473?v=4)](https://github.com/techwritermat "techwritermat (2 commits)")[![jakub-grzesiowski](https://avatars.githubusercontent.com/u/162123404?v=4)](https://github.com/jakub-grzesiowski "jakub-grzesiowski (2 commits)")[![michaljolender](https://avatars.githubusercontent.com/u/100685005?v=4)](https://github.com/michaljolender "michaljolender (1 commits)")[![wdw8276](https://avatars.githubusercontent.com/u/3972439?v=4)](https://github.com/wdw8276 "wdw8276 (1 commits)")[![cgrice](https://avatars.githubusercontent.com/u/17614?v=4)](https://github.com/cgrice "cgrice (1 commits)")[![musashiwasajedi](https://avatars.githubusercontent.com/u/5163234?v=4)](https://github.com/musashiwasajedi "musashiwasajedi (1 commits)")[![cvconover](https://avatars.githubusercontent.com/u/704203?v=4)](https://github.com/cvconover "cvconover (1 commits)")

---

Tags

apipushreal-timerealtimeajax

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[mpociot/slack-client

A better Slack client, with RTM API support

51263.6k1](/packages/mpociot-slack-client)[oneforge/forexquotes

Library to fetch and parse realtime Forex quotes and convert currencies

7212.5k](/packages/oneforge-forexquotes)[bushlanov-dev/max-bot-api-client-php

Max Bot API Client library

281.6k](/packages/bushlanov-dev-max-bot-api-client-php)

PHPackages © 2026

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