Flag to enable compression of messages before publishing. Set the flag totrueto enable compression. Defaults tofalse. Messsages are compressed if their total size >=compressionBytesThreshold, whose default value has been experimentally derived after performance evaluations.
↳ compressionBytesThreshold
int
The threshold byte size above which messages are compressed. This only takes effect ifenableCompressionis set totrue. Defaults to240.
publish
Send messages to a batch queue.
Example:
$batchPublisher->publish([
'data' => 'An important message.'
]);
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud PubSub Client - Class BatchPublisher (2.13.2)\n\nVersion latestkeyboard_arrow_down\n\n- [2.13.2 (latest)](/php/docs/reference/cloud-pubsub/latest/BatchPublisher)\n- [2.13.1](/php/docs/reference/cloud-pubsub/2.13.1/BatchPublisher)\n- [2.12.0](/php/docs/reference/cloud-pubsub/2.12.0/BatchPublisher)\n- [2.11.3](/php/docs/reference/cloud-pubsub/2.11.3/BatchPublisher)\n- [2.10.1](/php/docs/reference/cloud-pubsub/2.10.1/BatchPublisher)\n- [2.9.1](/php/docs/reference/cloud-pubsub/2.9.1/BatchPublisher)\n- [2.8.2](/php/docs/reference/cloud-pubsub/2.8.2/BatchPublisher)\n- [2.7.0](/php/docs/reference/cloud-pubsub/2.7.0/BatchPublisher)\n- [2.6.0](/php/docs/reference/cloud-pubsub/2.6.0/BatchPublisher)\n- [2.5.2](/php/docs/reference/cloud-pubsub/2.5.2/BatchPublisher)\n- [2.4.0](/php/docs/reference/cloud-pubsub/2.4.0/BatchPublisher)\n- [2.3.0](/php/docs/reference/cloud-pubsub/2.3.0/BatchPublisher)\n- [2.2.1](/php/docs/reference/cloud-pubsub/2.2.1/BatchPublisher)\n- [2.1.2](/php/docs/reference/cloud-pubsub/2.1.2/BatchPublisher)\n- [1.50.0](/php/docs/reference/cloud-pubsub/1.50.0/BatchPublisher)\n- [1.49.0](/php/docs/reference/cloud-pubsub/1.49.0/BatchPublisher)\n- [1.48.0](/php/docs/reference/cloud-pubsub/1.48.0/BatchPublisher)\n- [1.47.0](/php/docs/reference/cloud-pubsub/1.47.0/BatchPublisher)\n- [1.46.5](/php/docs/reference/cloud-pubsub/1.46.5/BatchPublisher)\n- [1.45.2](/php/docs/reference/cloud-pubsub/1.45.2/BatchPublisher)\n- [1.44.0](/php/docs/reference/cloud-pubsub/1.44.0/BatchPublisher)\n- [1.43.2](/php/docs/reference/cloud-pubsub/1.43.2/BatchPublisher)\n- [1.42.1](/php/docs/reference/cloud-pubsub/1.42.1/BatchPublisher)\n- [1.41.3](/php/docs/reference/cloud-pubsub/1.41.3/BatchPublisher)\n- [1.40.1](/php/docs/reference/cloud-pubsub/1.40.1/BatchPublisher)\n- [1.39.3](/php/docs/reference/cloud-pubsub/1.39.3/BatchPublisher) \n| **Beta**\n|\n|\n| This library is covered by the [Pre-GA Offerings Terms](/terms/service-terms#1)\n| of the Terms of Service. Pre-GA libraries might have limited support,\n| and changes to pre-GA libraries might not be compatible with other pre-GA versions.\n| For more information, see the\n[launch stage descriptions](/products#product-launch-stages). \nReference documentation and code samples for the Cloud PubSub Client class BatchPublisher.\n\nPublishes messages to Google Cloud Pub\\\\Sub with background batching.\n\nExample: \n\n use Google\\Cloud\\PubSub\\PubSubClient;\n\n $pubsub = new PubSubClient();\n $batchPublisher = $pubsub-\u003etopic('my_topic')\n -\u003ebatchPublisher();\n\n $batchPublisher-\u003epublish([\n 'data' =\u003e 'An important message.'\n ]);\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ PubSub\n\nMethods\n-------\n\n### __construct\n\n### publish\n\nSend messages to a batch queue.\n\nExample: \n\n $batchPublisher-\u003epublish([\n 'data' =\u003e 'An important message.'\n ]);\n\n### publishDeferred\n\nSee also:\n\n- [Publish Message](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/publish)\n\nConstants\n---------\n\n### ID_TEMPLATE\n\n Value: 'pubsub-topic-%s'"]]