Motan - a cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services

Related tags

Frameworks motan-php
Overview

Motan-PHP

License https://travis-ci.org/weibocom/motan-php.svg?branch=master

Overview

Motan is a cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services.

This project is the PHP Motan implementation. Provides PHP motan client.

Quick Start

Installation

Using composer:

Just clone this project and add it to your composer.json.

WithOut Composer:

If you didn't use composer for php libraries management, you would install motan-php by hand,like git clone, please check the demo at motan-example .

Usage:

we need an defined constant MOTAN_PHP_ROOT for load the motan php libs. Just like the demo does.

define('MOTAN_PHP_ROOT', './vendor/motan/motan-php/src/Motan/');
require MOTAN_PHP_ROOT . 'init.php';

The quick start gives very basic example of running client and server on the same machine. For the detailed information about using and developing Motan, please jump to Documents. the demo case is in the main/ directory

Motan server

We use Weibo-Mesh to support a PHP Server, Weibo-Mesh is a local agent writen in Golang. But not only a agent, Wei-Mesh take the ability as service governance. There is an example at motan-example

As a CGI agent to php-fpm

  cgi-mesh-example-helloworld:
    path: com.weibo.motan.HelloWorldService
    export: "motan2:9991"
    provider: cgi
    CGI_HOST: 10.211.55.3
    CGI_PORT: 9000
    CGI_REQUEST_METHOD: GET
    CGI_SCRIPT_FILENAME: /motan-examples/php-server/index.php
    CGI_DOCUMENT_ROOT: /motan-examples/php-server
    basicRefer: mesh-server-basicService

As a HTTP agent to any HTTP Server

  http-mesh-example-helloworld:
    path: com.weibo.motan.HelloWorldService
    export: "motan2:9990"
    provider: http
    HTTP_REQUEST_METHOD: GET
    HTTP_URL: http://10.211.55.3:9900/http_server
    basicRefer: mesh-server-basicService

Motan Client

Here is a simple example about Motan Client, it will call a remote service provider by Weibo-Mesh Testhelper, you can find more example in the phpt tests, you can just run ./run.sh to find more.

$app_name = 'search';
$service = 'com.weibo.HelloMTService';
$group = 'motan-demo-rpc';
$remote_method = 'HelloW';
$params = ['idevz'=>'for weibo-mesh'];
$cx = new Motan\MClient( $app_name );
$request = new \Motan\Request($service, $remote_method, $params);
$request->setGroup($group);
try{
    $res = $cx->doCall($request);
} catch(Exception $e) {
    var_dump($e->getMessage());
}

Contributors

License

Motan is released under the Apache License 2.0.

Comments
  • php客户端java服务序列化问题

    php客户端java服务序列化问题

    服务提供方: java 服务调用方: php 两种情况: 1、服务提供方无法处理请求参数; 2、服务调用方无法解析返回结果 1: java服务方法

        public String sayHello(String name) {
            System.out.println("name: " + name);
            return "hello " + "GD" + " !";
        }
    

    php调用

    $rs = $cx->sayHello(['name'=>'']);
    

    异常:

    {"errcode":400,"errmsg":"call fail over 3 times.Exception:process request fail. errmsg:error_message: SimpleSerialization not support type:class java.lang.String, status: 503, error_code: 10001,r=-2620754180148297728","errtype":1}Motan\Protocol\Header Object
    (
        [_magic:Motan\Protocol\Header:private] => 61937
        [_msg_type:Motan\Protocol\Header:private] => 1
        [_version_status:Motan\Protocol\Header:private] => 9
        [_serialize:Motan\Protocol\Header:private] => 8
        [_request_id:Motan\Protocol\Header:private] => 1.5825989893561E+19
    )
    Array
    (
        [M_e] => {"errcode":400,"errmsg":"call fail over 3 times.Exception:process request fail. errmsg:error_message: SimpleSerialization not support type:class java.lang.String, status: 503, error_code: 10001,r=-2620754180148297728","errtype":1}
    )
    

    2: java服务方法

        public String sayHello() {
            return "hello GD !";
        }
    

    php调用同1,可以调用到服务,并返回结果,但是php无法解析 异常

    PHP Fatal error:  Uncaught Exception: Fail to Decode response body, got a no support type! in /home/wwwroot/zepra.com/motan/src/Motan/Serialize/Motan.php:104
    Stack trace:
    #0 /home/wwwroot/zepra.com/motan/src/Motan/Endpointer.php(96): Motan\Serialize\Motan->deserialize(NULL, '\nhello GD !')
    #1 /home/wwwroot/zepra.com/motan/src/Motan/Client.php(102): Motan\Endpointer->call()
    #2 /home/wwwroot/zepra.com/motan/test.php(13): Motan\Client->__call('sayHello', Array)
    #3 {main}
      thrown in /home/wwwroot/zepra.com/motan/src/Motan/Serialize/Motan.php on line 104
    

    Motan.php 104行 type为10

    opened by dreamshit 5
  • Error to read header_buffer

    Error to read header_buffer

    目前走的motan-go代理访问JAVA服务, JAVA服务后面会同步对接一个较耗时的服务(1~4秒处理时长) motan-go配置的6秒超时,如果JAVA服务耗时短则motan-php正常接收返回结果,但是如果耗时长,motan-php这边基本在2秒左右,报Error to read header_buffer异常, 这个异常是什么场景下会报 结合motan-go应该如何配置motan-php的超时时长?

    opened by GDSGD 4
  • add support for each Request can sets it's serialization type of MClient.

    add support for each Request can sets it's serialization type of MClient.

    Example of MClient->doMultiCall():

    $app_name = 'phpt-test-MClient';
    $group = "bj";
    $service = "com.mycompany.motan.DemoServer";
    $mcx = new \Motan\MClient($app_name);
    $req1 = new \Motan\Request($service, 'Hello', "motan-php-client-req1");
    $req2 = new \Motan\Request($service, 'Hello', "motan-php-client-req2");
    $req3 = new \Motan\Request($service, 'Hello', "motan-php-client-req3");
    $req1->setGroup($group);
    $req2->setGroup($group);
    $req3->setGroup($group);
    $req1->setSerialization("breeze");
    $req2->setSerialization("simple");
    $req3->setSerialization("breeze");
    
    $multi_res = $mcx->doMultiCall([
        $req1,
        $req2,
        $req3
    ]);
    
    foreach ([
                 $req1,
                 $req2,
                 $req3,
             ] as $k => $req) {
        $e = $multi_res->getException($req);
        if (!empty($e)) {
            var_dump("req" . ($k + 1) . " error " . $e);
        } else {
            var_dump($multi_res->getRs($req));
        }
    }
    

    Example of Client->multiCal():

    $url_str = 'motan2://127.0.0.1:8001/com.mycompany.motan.DemoServer?group=bj&serialize=breeze';
    $cx = new \Motan\Client();
    $multi_res0=$cx->multiCall([
        new \Motan\URL($url_str),
        new \Motan\URL($url_str),
        new \Motan\URL($url_str),
    ],"Hello","client-multiple-call");
    var_dump($multi_res0);
    
    opened by snail007 0
  • fix load local snapshot

    fix load local snapshot

    fix

    load local snapshot

    #0 [internal function]: Laravel\Lumen\Application->Laravel\Lumen\Concerns\{closure}(2, 'key_exists() ex...', '/home/work/oyst...', 72, Array)
    #1 /home/work/oyster/vendor/motan/motan-php/src/Motan/Cluster/LoadBalance.php(72): key_exists(Array, 'working')
    #2 /home/work/oyster/vendor/motan/motan-php/src/Motan/Endpointer.php(90): Motan\Cluster\LoadBalance->getNode()
    #3 /home/work/oyster/vendor/motan/motan-php/src/Motan/Endpointer.php(128): Motan\Endpointer->_buildConnection()
    #4 /home/work/oyster/vendor/motan/motan-php/src/Motan/Endpointer.php(101): Motan\Endpointer->_doSend(Object(Motan\Request))
    #5 /home/work/oyster/vendor/motan/motan-php/src/Motan/Cluster/Ha/Failfast.php(39): Motan\Endpointer->call(Object(Motan\Request))
    #6 /home/work/oyster/vendor/motan/motan-php/src/Motan/Cluster.php(127): Motan\Cluster\Ha\Failfast->call(Object(Motan\Cluster\LoadBalance\Random), Object(Motan\Request))
    #7 /home/work/oyster/vendor/motan/motan-php/src/Motan/Client.php(141): Motan\Cluster->call(Object(Motan\Request))
    
    opened by oGre222 0
  • Wrong definition

    Wrong definition

    https://github.com/weibocom/motan-php/blob/0b5e5e605e52a9503ed2a708281d83911fe2f448/src/Motan/Endpointer.php#L78-L95 Definition $request_obj in line 78 is useless. $req_obj is not defined in line 93, it might be $req_obj_data defined in line 92 ?

    opened by HyperLiar 0
  • PHP通过go agent调用java服务BUG

    PHP通过go agent调用java服务BUG

    go agent 需要通过版本等值组成的键查找服务是否存在: version := "0.1" if request.GetAttachment(mpro.MVersion) != "" { version = request.GetAttachment(mpro.MVersion) } ck := getClusterKey(request.GetAttachment(mpro.MGroup), version, request.GetAttachment(mpro.MProxyProtocol), request.GetAttachment(mpro.MPath)) 但是,我跟踪了下,通过php的doCall调用方法时,版本号根本就没有到agent这边来,是我用法错误吗?

    opened by byjamesCN 1
  • \Motan\Client的_call方法BUG

    \Motan\Client的_call方法BUG

    $request_id = $request_args = $request_header = NULL; isset($arguments[0]) && !empty($arguments[0]) && $request_args = $arguments[0]; $request = new \Motan\Request($this->_url_obj->getService(), $name, ...[$request_args]); isset($arguments[1]) && !empty($arguments[1]) && $request->addHeaders($arguments[1]); isset($arguments[2]) && !empty($arguments[2]) && $request->setRequestId($arguments[2]); $request->setGroup($this->_url_obj->getGroup()); $http_params = $this->_url_obj->getParams();

    这上面的写法决定了通过_call调用某个远程方法时,只能支持一个参数吧? ...[$request_args],这个地方是否还要判断下?

    opened by byjamesCN 0
  • composer安装,包没找到

    composer安装,包没找到

    composer require motan/motan-php

    Could not find a matching version of package motan/motan-php. Check the package spelling, your version constraint a nd that the package is available in a stability which matches your minimum-stability (dev).

    opened by fenghoer 2
Releases(v1.1.8)
Owner
Weibo R&D Open Source Projects
Weibo R&D Open Source Projects
High-Performance Long-Living PHP Framework for modern enterprise application development

Documentation · Discord · Telegram · Twitter Spiral Framework is a High-Performance Long-Living Full-Stack framework and group of over sixty PSR-compa

Spiral Scout 1.4k Jan 1, 2023
CakePHP: The Rapid Development Framework for PHP - Official Repository

CakePHP is a rapid development framework for PHP which uses commonly known design patterns like Associative Data Mapping, Front Controller, and MVC. O

CakePHP 8.6k Dec 31, 2022
Elgg is an open source rapid development framework for socially aware web applications.

Elgg Elgg is an open source rapid development framework for socially aware web applications. Features Well-documented core API that allows developers

Elgg 1.6k Dec 27, 2022
Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components

Spiral HTTP Application Skeleton Spiral Framework is a High-Performance PHP/Go Full-Stack framework and group of over sixty PSR-compatible components.

Spiral Scout 152 Dec 18, 2022
High performance, full-stack PHP framework delivered as a C extension.

Phalcon Framework Phalcon is an open source web framework delivered as a C extension for the PHP language providing high performance and lower resourc

The Phalcon PHP Framework 10.7k Jan 8, 2023
Biny is a tiny, high-performance PHP framework for web applications

Biny is high performance. Framework comes default with response time of less than 1ms. Stand-alone QPS easily up to 3000.

Tencent 1.7k Dec 9, 2022
High performance HTTP Service Framework for PHP based on Workerman.

webman High performance HTTP Service Framework for PHP based on Workerman. Manual https://www.workerman.net/doc/webman Benchmarks https://www.techempo

walkor 1.3k Jan 2, 2023
🔥High Performance PHP Progressive Framework.

The Core Framework English | 中文 The QueryPHP Application QueryPHP is a modern, high performance PHP progressive framework, to provide a stable and rel

The QueryPHP Framework 306 Dec 14, 2022
💾 High-performance PHP application server, load-balancer and process manager written in Golang. RR2 releases repository.

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 45 Nov 29, 2022
🤯 High-performance PHP application server, load-balancer and process manager written in Golang

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 6.9k Jan 3, 2023
This package provides a high performance HTTP server to speed up your Laravel/Lumen application based on Swoole.

This package provides a high performance HTTP server to speed up your Laravel/Lumen application based on Swoole.

Swoole Taiwan 3.9k Jan 8, 2023
Asynchronous & Fault-tolerant PHP Framework for Distributed Applications.

Kraken PHP Framework ~ Release the Kraken! Note: This repository contains the core of the Kraken Framework. If you want to start developing new applic

Kraken 1.1k Dec 27, 2022
Zephir is a compiled high level language aimed to the creation of C-extensions for PHP.

Zephir - is a high level programming language that eases the creation and maintainability of extensions for PHP. Zephir extensions are exported to C c

Zephir Language 3.2k Dec 27, 2022
A system to help parents call their children inside the school when they are outside

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

null 1 Jan 15, 2022
Light, concurrent RPC framework for PHP & C

Yar - Yet Another RPC framework for PHP Light, concurrent RPC framework for PHP(see also: Yar C framework, Yar Java framework) Requirement PHP 7.0+ (m

Xinchen Hui 1.4k Dec 28, 2022
This package has framework agnostic Cross-Origin Resource Sharing (CORS) implementation.

Description This package has framework agnostic Cross-Origin Resource Sharing (CORS) implementation. It is complaint with PSR-7 HTTP message interface

null 60 Nov 9, 2022
DoraRPC is an RPC For the PHP MicroService by The Swoole

Dora RPC 简介(Introduction) Dora RPC 是一款基础于Swoole定长包头通讯协议的最精简的RPC, 用于复杂项目前后端分离,分离后项目都通过API工作可更好的跟踪、升级、维护及管理。 问题提交: Issue For complex projects separation

Chang Long Xu 468 Jan 5, 2023
Sunhill Framework is a simple, fast, and powerful PHP App Development Framework

Sunhill Framework is a simple, fast, and powerful PHP App Development Framework that enables you to develop more modern applications by using MVC (Model - View - Controller) pattern.

Mehmet Selcuk Batal 3 Dec 29, 2022
Jin microservices is a complete microservice demo based on PHP language + hyperf microservices framework

介绍 Jin-microservices是基于 php 语言 + hyperf 微服务 框架的完整微服务demo。 github:https://github.com/Double-Jin/jin-microservices gitee:https://gitee.com/ljj96/jin-mic

null 114 Dec 29, 2022