承接 protobuf-php/protobuf-plugin 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

protobuf-php/protobuf-plugin

Composer 安装命令:

composer require protobuf-php/protobuf-plugin

包简介

PHP Code generator plugin from Google's Protocol Buffers

README 文档

README

Build Status Coverage Status

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

If you wish to compile .proto definitions to PHP, you will need to install Google's Protocol Buffers 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, It is only necessary if you wish to compile your definitions to PHP using protobuf-php/protobuf-plugin.

Installing Google's 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 : https://github.com/google/protobuf

Composer install

To install the PHP plugin run the following composer commands:

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

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. 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 .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

protobuf-php/protobuf-plugin 适用场景与选型建议

protobuf-php/protobuf-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 145.69k 次下载、GitHub Stars 达 57, 最近一次更新时间为 2015 年 11 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「protobuf」 「protocol buffer」 「serializing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 protobuf-php/protobuf-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 protobuf-php/protobuf-plugin 我们能提供哪些服务?
定制开发 / 二次开发

基于 protobuf-php/protobuf-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 145.69k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 60
  • 点击次数: 27
  • 依赖项目数: 21
  • 推荐数: 0

GitHub 信息

  • Stars: 57
  • Watchers: 5
  • Forks: 29
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-11-18