PHPackages                             twipi-group/googlecloud-pubsub-php-adapter - 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. twipi-group/googlecloud-pubsub-php-adapter

ActiveLibrary[API Development](/categories/api)

twipi-group/googlecloud-pubsub-php-adapter
==========================================

PHP Adapter class for google-cloud-php-pubsub package.

1.1.0(6y ago)021831MITPHPPHP ~7.1CI failing

Since Apr 27Pushed 6y ago1 watchersCompare

[ Source](https://github.com/twipi-group/googlecloud-pubsub-php-adapter)[ Packagist](https://packagist.org/packages/twipi-group/googlecloud-pubsub-php-adapter)[ RSS](/packages/twipi-group-googlecloud-pubsub-php-adapter/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (3)Versions (5)Used By (1)

googlecloud-pubsub-php-adapter
==============================

[](#googlecloud-pubsub-php-adapter)

A Php class adapter for the [Goolge Cloud PubSub](https://github.com/googleapis/google-cloud-php-pubsub) package.

[![CI](https://github.com/twipi-group/googlecloud-pubsub-php-adapter/workflows/CI/badge.svg)](https://github.com/twipi-group/googlecloud-pubsub-php-adapter/workflows/CI/badge.svg)[![Minimum PHP Version](https://camo.githubusercontent.com/7a09b828563f7738e2e72ec4aade8144538bf5d41e1e2e718815c57e3416089f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230372e312d3838393242462e7376673f7374796c653d666c6174)](https://www.php.net/manual/fr/migration71.new-features.php)[![Software License](https://camo.githubusercontent.com/ef5b59ada4f12bb5a3dc4f948e83be4f8914189d6b2fb526869160e586f49e69/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e7376673f7374796c653d666c6174)](LICENSE)

Installation
------------

[](#installation)

```
composer require twipi-group/googlecloud-pubsub-php-adapter
```

Samples
-------

[](#samples)

### Publish

[](#publish)

```
use Google\Cloud\PubSub\PubSubClient;
use TwipiGroup\GoogleCloudPubSubPhpAdapter\GcPubSub;

$client = new PubSubClient([
    'projectId' => 'your-googlecloud-project-id',
]);

$pubsub = new GcPubSub($client);

$pubsub->publish('mychannel', 'test first');
$pubsub->publish('mychannel', json_encode(['test' => 'another']));
$pubsub->publish('mytopic', [
    'test' => [0, 1, 2]
]);
```

### Consume

[](#consume)

```
use Google\Cloud\PubSub\PubSubClient;
use TwipiGroup\GoogleCloudPubSubPhpAdapter\GcPubSub;

$client = new PubSubClient([
    'projectId' => 'your-googlecloud-project-id',
]);

$pubsub = new GcPubSub($client);

// case blocking call
$pubsub->subscribe('mychannel', function ($message) {
    var_dump($message);
});
// OR
$pubsub->subscribe('mysubscriber', function ($message) {
    var_dump($message);
}, 'mytopic');

// case non blocking call
$messages = $pubsub->consume('mychannel');
// OR
$messages = $pubsub->consume('mysubscriber', 'mytopic');

foreach ($messages as $message) {
    var_dump($message);
}
```

Functions
---------

[](#functions)

### Uses

[](#uses)

`function createTopic(string $topicName): Topic`

This function creates a topic from **$topicName** and returns topic object.

`function getTopic(string $topicName): Topic`

This function returns an existing topic object from **$topicName** or create a new topic if **setAutoCreateTopic** is *true*. If **setAutoCreateTopic** is *false*, an exception will be thrown.

`function deleteTopic(string $topicName): Topic`

This function deletes an existing topic from **$topicName** and returns topic object.

`function updateTopic($topicName, $properties): Topic`

This function updates an existing topic from **$topicName** and returns topic object. Note that the topic's name and kms key name are immutable properties and may not be modified.

`function getTopics(): array`

This function returns an array of existing topics objects.

`function deleteTopics(): array`

This function deletes all existing topics and returns array of topics name deleted.

`function createSubscription(string $subscriptionName, string $topicName = ''): Subscription`

This function creates a topic from **$subscriptionName** and returns subscription object. If **setAutoCreateTopicFromSubscription** and **setAutoCreateTopic** are *true* and **$topicName** is *empty*, so a topic will be created from **$subscriptionName**.

`function getSubscription(string $subscriptionName, string $topicName = ''): Subscription`

This function returns an existing subscription object from **$subscriptionName** or create a new subscription if **setAutoCreateSubscription** is *true*. If **setAutoCreateSubscription** is *false*, an exception will be thrown. If **setAutoCreateTopicFromSubscription** and **setAutoCreateTopic** are *true* and **$topicName** is *empty*, so a topic will be created from **$subscriptionName**. If **setAutoCreateTopicFromSubscription** or **setAutoCreateTopic** is *false* and **$topicName** is *empty*, an exception will be thrown.

`function deleteSubscription($subscriptionName): Subscription`

This function deletes an existing subscription from **$subscriptionName** and returns subscription object.

`function updateSubscription($subscriptionName, $properties): Subscription`

This function updates an existing subscription from **$subscriptionName** and returns subscription object. Note that subscription name and topic are immutable properties and may not be modified.

`function getSubscriptions(): array`

This function returns an array of existing subscriptions objects.

`function consume(string $subscriptionName, string $topicName = ''): array`

This function always return immediately after one pull. You just can change setMaxMessages for receiving x messages from this pull. If **setAutoCreateTopic** and **setAutoCreateTopicFromSubscription** are *true*, and if **$topicName** is *empty*, it will auto create topic from subscription name if topic not already exists. This function returns an array of messages.

`function subscribe(string $subscriptionName, callable $handler, string $topicName = '', $infiniteLoop = true): void`

This function is an infinite loop by default thanks to *$infiniteLoop = true*.

- if **$infiniteLoop** is *true* :

    - if **setReturnImmediately** is *true* and **setDelay** &gt; 1 second, the loop will sleep every one second between each pull
    - if **setReturnImmediately** is *true* and **setDelay** = 0 second, the loop will work everytime, this **IS NOT RECOMMENDED** because it adversely impacts the performance of the system.
    - if **setReturnImmediately** is *false*, (**RECOMMENDED**) the system waits (~90 seconds) until at least one message is available, and **setDelay** has no effect.
- if **$infiniteLoop** is *false* :

    - **setReturnImmediately** and **setDelay** has no impact because just one loop will be executed with only one pull.

#### Settings

[](#settings)

```
// set max messages number consuming by pull
$pubsub->setMaxMessages(2); // 100 by default

// set if return immediately after pull
$pubsub->setReturnImmediately(true); // false by default

// set delay in seconds to wait between each pull
// note: if ReturnImmediately is false, this option has no effect.
$pubsub->setDelay(2); // 10 by default

// set a suffix for subscriptions
$pubsub->setTopicSuffix('mysubsriber_'); // empty by default

// set debug mode to display pull messages directly to output
$pubsub->setDebug(true); // false by default

// set if auto create topic when not existing
$pubsub->setAutoCreateTopic(false); // true by default

// set if auto create subscription when not existing
$pubsub->setAutoCreateSubscription(false); // true by default

// set if auto create topic from subscription name when consume messages with empty topic name
$pubsub->setAutoCreateTopicFromSubscription(false); // true by default
```

Tests
-----

[](#tests)

```
vendor/bin/phpunit Tests

```

Contribution
------------

[](#contribution)

You can contribute to this package by discovering bugs, opening issues or purpose new features.

Licence
-------

[](#licence)

This project is licensed under the terms of the MIT license. See License file for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

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

Total

2

Last Release

2198d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7486438?v=4)[missill](/maintainers/missill)[@missill](https://github.com/missill)

---

Top Contributors

[![missill](https://avatars.githubusercontent.com/u/7486438?v=4)](https://github.com/missill "missill (8 commits)")[![Barbours](https://avatars.githubusercontent.com/u/64016237?v=4)](https://github.com/Barbours "Barbours (6 commits)")

---

Tags

phpadapterpubsubgcpgooglecloud

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/twipi-group-googlecloud-pubsub-php-adapter/health.svg)

```
[![Health](https://phpackages.com/badges/twipi-group-googlecloud-pubsub-php-adapter/health.svg)](https://phpackages.com/packages/twipi-group-googlecloud-pubsub-php-adapter)
```

PHPackages © 2026

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