PHPackages                             milind/php-pubsub-google-cloud - 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. milind/php-pubsub-google-cloud

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

milind/php-pubsub-google-cloud
==============================

A Google Cloud adapter for the php-pubsub package

08PHP

Since Jul 15Pushed 5y agoCompare

[ Source](https://github.com/little-isaac/php-pubsub-google-cloud)[ Packagist](https://packagist.org/packages/milind/php-pubsub-google-cloud)[ RSS](/packages/milind-php-pubsub-google-cloud/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

php-pubsub-google-cloud
=======================

[](#php-pubsub-google-cloud)

A Google Cloud adapter for the [php-pubsub](https://github.com/milind/php-pubsub) package.

[![Author](https://camo.githubusercontent.com/89d1829c61afc8a92333fe0e830ad71714d9fa0cb84cea315ba6162304ff688b/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d406d696c696e642d626c75652e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/milind)[![Build Status](https://camo.githubusercontent.com/7358288bc7e8847efad12f33c13deff6923d306ae3c87a7f0a0ff15379983f33/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d696c696e642f7068702d7075627375622d676f6f676c652d636c6f75642f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/milind/php-pubsub-google-cloud)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Packagist Version](https://camo.githubusercontent.com/cf9aa8d2025279751613a1ee8982eae6622c2311fac909d788388b1a37548fbc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d696c696e642f7068702d7075627375622d676f6f676c652d636c6f75642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/milind/php-pubsub-google-cloud)[![Total Downloads](https://camo.githubusercontent.com/1d694103b597a154e421c2c3dd8d13bfe44eec3bce3686b4d52beb223d63a40a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d696c696e642f7068702d7075627375622d676f6f676c652d636c6f75642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/milind/php-pubsub-google-cloud)

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

[](#installation)

```
composer require milind/php-pubsub-google-cloud
```

Usage
-----

[](#usage)

```
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . __DIR__ . '/../your-gcloud-key.json');

$client = new \Google\Cloud\PubSub\PubSubClient([
    'projectId' => 'your-project-id-here',
]);

$adapter = new \milind\PubSub\GoogleCloud\GoogleCloudPubSubAdapter($client);

// disable auto topic & subscription creation
$adapter->setAutoCreateTopics(false); // this is true by default
$adapter->setAutoCreateSubscriptions(false); // this is true by default

// set a unique client identifier for the subscriber
$adapter->setClientIdentifier('search_service');

// consume messages
// note: this is a blocking call
$adapter->subscribe('my_channel', function ($message) {
    var_dump($message);
});

// publish messages
$adapter->publish('my_channel', 'HELLO WORLD');
$adapter->publish('my_channel', json_encode(['hello' => 'world']));
$adapter->publish('my_channel', 1);
$adapter->publish('my_channel', false);
```

gRPC Support
------------

[](#grpc-support)

Google Cloud PHP v0.12.0 added support for communication over the gRPC protocol.

> gRPC is great for high-performance, low-latency applications, and is highly recommended in cases where performance and latency are concerns.

The library will automatically choose gRPC over REST if all dependencies are installed.

- [gRPC PECL extension](https://pecl.php.net/package/gRPC)
- [google/proto-client-php composer package](https://github.com/googleapis/gax-php)
- [googleapis/proto-client-php composer package](https://github.com/googleapis/proto-client-php)

```
pecl install grpc

composer require google/gax
composer require google/proto-client
```

Background Batch Message Support
--------------------------------

[](#background-batch-message-support)

Google Cloud v0.33.0 added support for queueing messages and publishing in the background. This is available in version 5+ of this package which requires a min version of google/cloud ^0.33.0.

You can enable background batch messaging by setting `$backgroundBatching` to `true` when constructing the `GoogleCloudPubSubAdapter` or by calling `setBackgroundBatching(true)` on an existing adapter.

If the [semaphore](http://php.net/manual/en/book.sem.php) and [pcntl](http://php.net/manual/en/book.pcntl.php) PHP extensions are enabled AND the `IS_BATCH_DAEMON_RUNNING` ENV var is set to `true`, the library will queue messages to be published by the [Batch Daemon](https://github.com/GoogleCloudPlatform/google-cloud-php/blob/master/src/Core/Batch/BatchDaemon.php). The Batch Daemon needs to be manually run as a long-lived background process.

For all other cases, messages will be queued in memory and will be published before the script terminates using a vendor registered shutdown handler.

**Please Note**

This is marked by google/cloud as an experimental feature &amp; may change before release in backwards-incompatible ways.

Examples
--------

[](#examples)

The library comes with [examples](examples) for the adapter and a [Dockerfile](Dockerfile) for running the example scripts.

Run `make up`.

You will start at a `bash` prompt in the `/opt/php-pubsub` directory.

If you need another shell to publish a message to a blocking consumer, you can run `docker-compose run php-pubsub-google-cloud /bin/bash`

To run the examples:

```
$ php examples/GoogleCloudConsumerExample.php
$ php examples/GoogleCloudPublishExample.php (in a separate shell)
```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 66% 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://www.gravatar.com/avatar/dd0035e6fda13036e33240c5018bba0914101219b774998cebb073c4a7ef2abe?d=identicon)[little-isaac](/maintainers/little-isaac)

---

Top Contributors

[![matthewgoslett](https://avatars.githubusercontent.com/u/1571743?v=4)](https://github.com/matthewgoslett "matthewgoslett (31 commits)")[![geyer-za](https://avatars.githubusercontent.com/u/6848791?v=4)](https://github.com/geyer-za "geyer-za (15 commits)")[![nicja](https://avatars.githubusercontent.com/u/2102143?v=4)](https://github.com/nicja "nicja (1 commits)")

### Embed Badge

![Health badge](/badges/milind-php-pubsub-google-cloud/health.svg)

```
[![Health](https://phpackages.com/badges/milind-php-pubsub-google-cloud/health.svg)](https://phpackages.com/packages/milind-php-pubsub-google-cloud)
```

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25026.8M85](/packages/php-http-cache-plugin)[httpsoft/http-message

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

85997.3k131](/packages/httpsoft-http-message)[thesis/nats

Async (fiber based) client for Nats.

758.3k](/packages/thesis-nats)

PHPackages © 2026

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