Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sofa-pbrpc php 扩展 #73

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,3 @@ For performace details, please refer to the wiki.
### Support
[email protected]

### User List
If sofa-pbrpc is used in your product, please record your user information in the belowing table with a new line,
so that communication between users can be more convenient, and new features will be better notified.

| company | product line | cluster scale | owner | recommendation |
| -------:| ------------:| -------------:| -----:| --------------:|
36 changes: 36 additions & 0 deletions php/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This directory contains the php extension for sofa-pbrpc client.

Installation
============

1) Make sure your PHP version is at least 5.4 and you have installed sofa-pbrpc library in sofa-pbrpc output

2) Because this lib depends on the "allegro/php-protobuf" lib to serialize and unserialize data,

You should install the allegro/php-protobuf and use this lib in your PHP codes and you can get

"allegro/php-protobuf" on this page:

https://github.com/allegro/php-protobuf

3) Change the dependences path:

Change the dependences path "RPCLIB_DIR" and "PROTOBUFLIB_DIR" in comfig.m4

4) Build the extension

Run "/usr/local/php/bin/phpize ./config.m4"

"./configure --with-php-config=/usr/local/php/bin/php-config" to generate Makefile

Run "make clean && make -j10 && make install" to build the extension

You can get extension in ./modules

5) Generate PHP interface

You can generate PHP interface like this:

"php -c /usr/etc/php.ini protoc-php.php test.proto"

You can get a simple usage in ./sample
33 changes: 33 additions & 0 deletions php/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2016 Baidu.com, Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Author: [email protected] (Zhangdi Di)

#ifndef COMMON_H
#define COMMON_H

#include <string>

namespace sofa_php_ext
{

#define EXT_ZEND_FOREACH(iter, hash) \
for (zend_hash_internal_pointer_reset_ex((hash), (iter)); \
zend_hash_has_more_elements_ex((hash), (iter)) == SUCCESS; \
zend_hash_move_forward_ex((hash), (iter)))

const static std::string PB_VALUES_PROPERTY = "values";
const static std::string PB_FIELDS_METHOD = "fields";
const static std::string PB_FIELD_TYPE = "type";
const static std::string PB_FIELD_REQUIRED = "required";
const static std::string PB_FIELD_REPEATED = "repeated";
const static std::string PB_FIELD_NAME = "name";
const static std::string CLASS_TYPE = "class_type";
const static std::string PARSE_FUNCTION = "parseFromString";
static const char* IMPL = "impl";

}
#endif // COMMON_H

/* vim: set ts=4 sw=4 sts=4 tw=100 */
24 changes: 24 additions & 0 deletions php/config.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
dnl $Id$
dnl config.m4 for extension sofa-pbrpc
PHP_ARG_ENABLE(sofa_pbrpc, whether to enable sofa_pbrpc support,
[ --enable-sofa_pbprc enable sofa_pbrpc support])

if test "$PHP_SOFAPBRPC" != "no"; then
RPC_LIBNAME=sofa-pbrpc
RPCLIB_DIR=/usr/local/sofa-pbrpc
PROTOBUF_LIBNAME=protobuf
PROTOBUFLIB_DIR=/usr/local/protobuf
PHP_REQUIRE_CXX()
PHP_SUBST(SOFA_PBRPC_SHARED_LIBADD)
PHP_ADD_LIBRARY(stdc++, 1, SOFA_PBRPC_SHARED_LIBADD)

PHP_ADD_LIBRARY(sofa-pbrpc, 1, SOFA_PBRPC_SHARED_LIBADD)
PHP_ADD_LIBRARY_WITH_PATH($RPC_LIBNAME, $RPCLIB_DIR/output/lib)
PHP_ADD_INCLUDE($RPCLIB_DIR/output/include)
PHP_ADD_LIBRARY(protobuf, 1, SOFA_PBRPC_SHARED_LIBADD)
PHP_ADD_LIBRARY_WITH_PATH($PROTOBUF_LIBNAME, $PROTOBUFLIB_DIR/lib)
PHP_ADD_INCLUDE($PROTOBUFLIB_DIR/include)
PHP_NEW_EXTENSION(sofa_pbrpc, ext_rpc_service_stub.cc ext_rpc_service_stub_impl.cc, $ext_shared)
fi

PHP_C_BIGENDIAN()
Loading