What are the avaliable libraries for using protobuf in PHP?
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.
Proto3 is the latest version of Protocol Buffers and includes the following changes from proto2: Field presence, also known as hasField , is removed by default for primitive fields. An unset primitive field has a language-defined default value.
Proto2: supports optional natively, the wrapper types were recommended but should be avoided in new applications. Proto3: originally did not support presence tracking for primitive fields. As of 2020, proto3 supports both optional fields which have has_foo() methods and "singular" fields, which do not.
Protobuf achieves good compression ratios through varint encoding. It might not be necessary to add an extra layer of compression in most cases.
There is also https://github.com/drslump/Protobuf-PHP
Last updated December 2013.
Requirements (from the Github page):
GMP or BC Math extensions ¹
¹ Only needed for negative values in int32, int64 or fixed64 types. See the known issues section.
Protocol_Buffer_for_PHP
Last updated in May 2009
Implementing the Google "Protocol Buffer" for PHP, include parsing ...
Issue list: http://code.google.com/p/pb4php/issues/list
Protobuf-PHP
Last updated in April 2011
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.
Great effort has been put into generating PHP files that include all sort of type hints to aide IDE's with autocompletion. Therefore, it can not only be used to communicate with Protocol Buffers services but also as a generation tool for data objects no matter what the final serialization is.
Example:
$person = new Tutorial\Person();
$person->name = 'DrSlump';
$person->setId(12);
$book = new Tutorial\AddressBook();
$book->addPerson($person);
// Use default codec
$data = $book->serialize();
// Use custom codec
$codec = new \DrSlump\Protobuf\Codec\Binary();
$data = $codec->encode($book);
// ... or ...
$data = $book->serialize($codec);
protoc-gen-php
Last updated December 05, 2010
This is a PHP Google Protocol Buffer Generator Plugin for protoc. It generates PHP code from a .proto file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With