Download the PHP package protobuf-php/protobuf without Composer

On this page you can find all versions of the php package protobuf-php/protobuf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package protobuf

Protobuf for PHP

Build Status Coverage Status Total Downloads License

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

Run the following composer commands:

Overview

This tutorial provides a basic introduction to working with protocol buffers. By walking through creating a simple example application, it shows you how to

Why Use Protocol Buffers?

The example we're going to use is a very simple "address book" application that can read and write people's contact details to and from a file. Each person in the address book has a name, an ID, an email address, and a contact phone number.

How do you serialize and retrieve structured data like this? There are a few ways to solve this problem:

Protocol buffers are the flexible, efficient, automated solution to solve exactly this problem. With protocol buffers, you write a description of the data structure you wish to store. From that, the protocol buffer compiler creates a class that implements automatic encoding and parsing of the protocol buffer data with an efficient binary format. The generated class provides getters and setters for the fields that make up a protocol buffer and takes care of the details of reading and writing the protocol buffer as a unit. Importantly, the protocol buffer format supports the idea of extending the format over time in such a way that the code can still read data encoded with the old format.

Defining Your Protocol Format

To create your address book application, you'll need to start with a file. The definitions in a 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 file that defines your messages, .

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 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 , as we have here. Even if you do provide a , 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.

After the package declaration, you can see two options that are PHP-specific: and .

Next, you have your message definitions. A message is just an aggregate containing a set of typed fields. Many standard simple data types are available as field types, including , , , , and . You can also add further structure to your messages by using other message types as field types – in the above example the message contains messages, while the message contains messages. You can even define message types nested inside other messages – as you can see, the type is defined inside . You can also define types if you want one of your fields to have one of a predefined list of values – here you want to specify that a phone number can be one of , , or .

The , markers on each element identify the unique that field uses in the binary encoding. Tag numbers 1-15 require one less byte to encode than higher numbers, so as an optimization you can decide to use those tags for the commonly used or repeated elements, leaving tags 16 and higher for less-commonly used optional elements. Each element in a repeated field requires re-encoding the tag number, so repeated fields are particularly good candidates for this optimization.

Each field must be annotated with one of the following modifiers:

You'll find a complete guide to writing .proto files – including all the possible field types – in the Protocol Buffer Language Guide. Don't go looking for facilities similar to class inheritance, though – protocol buffers don't do that.

Compiling Your Protocol Buffers

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

If you haven't installed the compiler () or you dont have the php plugin, see https://github.com/protobuf-php/protobuf-plugin.

Now run the compiler plugin, specifying the proto files source directory (the file directory is used if you don't provide a value), the destination directory (where you want the generated code to go), and the path to your In this case:

This generates the following PHP classes in your specified destination directory

The Protocol Buffer API

Let's look at some of the generated code and see what classes and methods the compiler has created for you. If you look in you can see that it defines a class called .

Messages have auto-generated accessor methods for each field of the message. Here are some of the accessors for the Person class (implementations omitted for brevity):

As you can see, there are simple getters and setters for each field. There are also has getters for each singular field which return true if that field has been set. Repeated fields have a extra method, an add method which appends a new element to the list.

Notice how these accessor methods use camel-case naming, even though the file uses lowercase-with-underscores. This transformation is done automatically by the protocol buffer compiler so that the generated classes match standard PHP style conventions. You should always use lowercase-with-underscores for field names in your files; this ensures good naming practice in all the generated languages. See the style guide for more on good style.

Protocol Buffers types map to the following PHP types:

Protocol Buffers PHP
double float
float float
int32 int
int64 int
uint32 int
uint64 int
sint32 int
sint64 int
fixed32 int
fixed64 int
sfixed32 int
sfixed64 int
bool bool
string string
bytes \Protobuf\Stream

Enums and Nested Classes

The generated code includes a enum:

All nested types are generated using the parent class as part of its namespace.

Known issues

Parsing and Serialization

Each protocol buffer class has methods for writing and reading messages of your chosen type using the protocol buffer binary format. These include :

Writing A Message

Now let's try using your protocol buffer classes. The first thing you want your address book application to be able to do is write personal details to your address book file. To do this, you need to create and populate instances of your protocol buffer classes and then write them to an output stream.

Here is a program which reads an from a file, adds one new to it based on user input, and writes the new back out to the file again. The parts which directly call or reference code generated by the protocol compiler are highlighted.

This tutorial documentation its based on the Protocol Buffer Basics Tutorial.


All versions of protobuf with dependencies

PHP Build Version
Package Version
Requires ext-mbstring Version *
php Version >=5.5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package protobuf-php/protobuf contains the following files

Loading the files please wait ....