PHPackages                             protobuf-php-8/protobuf-plugin - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. protobuf-php-8/protobuf-plugin

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

protobuf-php-8/protobuf-plugin
==============================

PHP Code generator plugin from Google's Protocol Buffers

01PHP

Since Sep 19Pushed 2y agoCompare

[ Source](https://github.com/KirillTsvetkov/protobuf-plugin)[ Packagist](https://packagist.org/packages/protobuf-php-8/protobuf-plugin)[ RSS](/packages/protobuf-php-8-protobuf-plugin/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Protobuf for PHP
================

[](#protobuf-for-php)

[![Build Status](https://camo.githubusercontent.com/3d21be5355c89b9f58d60a66b664a2bc62dd5304b6869a73a7bbef0f56397eb3/68747470733a2f2f7472617669732d63692e6f72672f70726f746f6275662d7068702f70726f746f6275662d706c7567696e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/protobuf-php/protobuf-plugin)[![Coverage Status](https://camo.githubusercontent.com/f4017d42c465a8c07db62626d38c5d32c691fb46f8ad48203633845226ef507b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f70726f746f6275662d7068702f70726f746f6275662d706c7567696e2f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/protobuf-php/protobuf-plugin?branch=master)

Protobuf for PHP is an implementation of Google's Protocol Buffers for the PHP language, supporting its binary data serialization and including a `protoc`plugin to generate PHP classes from `.proto` files.

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

[](#installation)

If you wish to compile `.proto` definitions to PHP, you will need to install [Google's Protocol Buffers](https://github.com/google/protobuf) from your favorite package manager or from source. This plugin currently supports protobuf 2.3.0. or later.

**Note**: *Google's Protocol Buffers and `proto` is not a runtime requirement for [protobuf-php/protobuf](https://github.com/protobuf-php/protobuf), It is only necessary if you wish to compile your definitions to PHP using [protobuf-php/protobuf-plugin](https://github.com/protobuf-php/protobuf-plugin).*

#### Installing Google's Protocol Buffers

[](#installing-googles-protocol-buffers)

- **OSX Install**

```
$ brew install protobuf
```

- **Ubuntu**

```
$ sudo apt-get install -y protobuf
```

Make sure you have `protoc` available in the user's path:

```
$ protoc --version
$ # libprotoc 2.6.1
```

**Note**: *For more information on how to install/compile Google's Protocol Buffers see : *

#### Composer install

[](#composer-install)

To install the PHP plugin run the following `composer` commands:

```
$ composer require "protobuf-php/protobuf-plugin"
```

#### Defining Your Protocol Format

[](#defining-your-protocol-format)

To create your address book application, you'll need to start with a `.proto` file. The definitions in a `.proto` file are simple: you add a message for each data structure you want to serialize, then specify a name and a type for each field in the message. Here is the `.proto` file that defines your messages, `addressbook.proto`.

```
package tutorial;
import "php.proto";
option (php.package) = "Tutorial.AddressBookProtos";

message Person {
  required string name = 1;
  required int32 id = 2;
  optional string email = 3;

  enum PhoneType {
    MOBILE = 0;
    HOME = 1;
    WORK = 2;
  }

  message PhoneNumber {
    required string number = 1;
    optional PhoneType type = 2 [default = HOME];
  }

  repeated PhoneNumber phone = 4;
}

message AddressBook {
  repeated Person person = 1;
}
```

As you can see, the syntax is similar to C++ or Java. Let's go through each part of the file and see what it does. The `.proto` file starts with a package declaration, which helps to prevent naming conflicts between different projects. In PHP, the package name is used as the PHP namespace unless you have explicitly specified a `(php.package)`, as we have here. Even if you do provide a `(php.package)`, you should still define a normal package as well to avoid name collisions in the Protocol Buffers name space as well as in non PHP languages.

You'll find a complete guide to writing `.proto` files – including all the possible field types – in the [Protocol Buffer Language Guide](https://developers.google.com/protocol-buffers/docs/proto). Don't go looking for facilities similar to class inheritance, though – protocol buffers don't do that.

#### Compiling Your Protocol Buffers

[](#compiling-your-protocol-buffers)

Now that you have a `.proto`, the next thing you need to do is generate the classes you'll need to read and write `AddressBook` (and hence `Person` and `PhoneNumber`) messages. To do this, you need to run the protocol buffer plugin on your `.proto`.

In this case:

```
php ./vendor/bin/protobuf --include-descriptors -i . -o ./src/ ./addressbook.proto
```

This generates the following PHP classes in your specified destination directory

```
src/
└── Tutorial
    └── AddressBookProtos
        ├── AddressBook.php
        ├── Person
        │   ├── PhoneNumber.php
        │   └── PhoneType.php
        └── Person.php
```

**Note**: *For more information on how to use the generated code see : [protobuf-php/protobuf](https://github.com/protobuf-php/protobuf)*

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 Bus Factor1

Top contributor holds 97.3% 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/9b2bdeb16730bd670d254913ecdf4d3c901945c0e3f6d4326ddbeb69bd8ab43c?d=identicon)[KirillTsvetkov](/maintainers/KirillTsvetkov)

---

Top Contributors

[![FabioBatSilva](https://avatars.githubusercontent.com/u/588172?v=4)](https://github.com/FabioBatSilva "FabioBatSilva (73 commits)")[![KirillTsvetkov](https://avatars.githubusercontent.com/u/56355589?v=4)](https://github.com/KirillTsvetkov "KirillTsvetkov (1 commits)")[![rodrigodiez](https://avatars.githubusercontent.com/u/823685?v=4)](https://github.com/rodrigodiez "rodrigodiez (1 commits)")

### Embed Badge

![Health badge](/badges/protobuf-php-8-protobuf-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/protobuf-php-8-protobuf-plugin/health.svg)](https://phpackages.com/packages/protobuf-php-8-protobuf-plugin)
```

PHPackages © 2026

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