PHP 协议缓冲区

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6224584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:42:03  来源:igfitidea点击:

Protocol Buffer for PHP

phpprotocol-buffers

提问by oluies

What are the avaliable libraries for using protobuf in PHP?

在 PHP 中使用 protobuf 的可用库有哪些?

采纳答案by oluies

Protocol_Buffer_for_PHP

Protocol_Buffer_for_PHP

Last updated in May 2009

最后更新于 2009 年 5 月

Implementing the Google "Protocol Buffer" for PHP, include parsing ...

为 PHP 实现 Google“协议缓冲区”,包括解析...

Issue list: http://code.google.com/p/pb4php/issues/list

问题列表:http: //code.google.com/p/pb4php/issues/list

Protobuf-PHP

Protobuf-PHP

Last updated in April 2011

最后更新于 2011 年 4 月

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.

PHP 的 Protobuf 是 Google 的 PHP 语言协议缓冲区的实现,支持其二进制数据序列化并包括一个 protoc 插件,用于从 .proto 文件生成 PHP 类。

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.

为生成包含各种类型提示以帮助 IDE 自动完成的 PHP 文件,我们付出了巨大的努力。因此,它不仅可以用于与 Protocol Buffers 服务进行通信,还可以作为数据对象的生成工具,无论最终序列化是什么。

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

protoc-gen-php

Last updated December 05, 2010

最后更新于 2010 年 12 月 5 日

This is a PHP Google Protocol Buffer Generator Plugin for protoc. It generates PHP code from a .proto file.

这是一个用于 protoc 的 PHP Google 协议缓冲区生成器插件。它从 .proto 文件生成 PHP 代码。

回答by j-a

There is also https://github.com/drslump/Protobuf-PHP

还有https://github.com/drslump/Protobuf-PHP

Last updated December 2013.

最后更新于 2013 年 12 月。

Requirements (from the Github page):

要求(来自 Github 页面):

  • PHP 5.3
  • Pear's Console_CommandLine (for the protoc wrapper tool)
  • Google's protoc compiler version 2.3 or above
  • GMP or BC Math extensions 1

    1 Only needed for negative values in int32, int64 or fixed64 types. See the known issues section.

  • PHP 5.3
  • Pear 的 Console_CommandLine(用于 protoc 包装工具)
  • Google 的 protoc 编译器 2.3 或更高版本
  • GMP 或 BC 数学扩展 1

    1 仅对 int32、int64 或 fixed64 类型中的负值需要。请参阅已知问题部分。

回答by Hubert Jagodziński

If performance is your concern you might try PHP Protobuf.

如果您关心性能,您可以尝试PHP Protobuf

It is PHP Protocol Buffers implementation written as an extension in C. Even though it is C code has no external dependencies including original Google's implementation.

它是 PHP Protocol Buffers 实现,以 C 语言扩展编写。即使它是 C 代码,也没有外部依赖项,包括原始 Google 的实现。

PHP Protobuf comes with quite complete documentation.

PHP Protobuf 附带了非常完整的文档。