• Stars
    star
    185
  • Rank 201,666 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created almost 8 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Hprose asynchronous client & standalone server based on swoole

Hprose

Hprose for Swoole

Build Status Supported PHP versions: 5.3 .. 7.1 Packagist Packagist Download License

Introduction

Hprose is a High Performance Remote Object Service Engine.

It is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware. It is not only easy to use, but powerful. You just need a little time to learn, then you can use it to easily construct cross language cross platform distributed application system.

Hprose supports many programming languages, for example:

  • AAuto Quicker
  • ActionScript
  • ASP
  • C++
  • Dart
  • Delphi/Free Pascal
  • dotNET(C#, Visual Basic...)
  • Golang
  • Java
  • JavaScript
  • Node.js
  • Objective-C
  • Perl
  • PHP
  • Python
  • Ruby
  • ...

Through Hprose, You can conveniently and efficiently intercommunicate between those programming languages.

This project is the implementation of Hprose for PHP based on swoole.

More Documents for Hprose 2.0: https://github.com/hprose/hprose-php/wiki

Installation

Download Source Code

Download Link

install by composer

{
    "require": {
        "hprose/hprose-swoole": "dev-master"
    }
}

Usage

You need to install swoole first. The minimum version of swoole been supported is 1.8.8.

You also need to install hprose-pecl 1.6.5+.

Server

Hprose for PHP is very easy to use.

You can create a standalone hprose http server like this:

http_server.php

<?php
    require_once "vendor/autoload.php";

    use Hprose\Swoole\Server;

    function hello($name) {
        return 'Hello ' . $name;
    }

    $server = new Server('http://0.0.0.0:80/');
    $server->addFunction('hello');
    $server->start();

tcp_server.php

<?php
    require_once "vendor/autoload.php";

    use Hprose\Swoole\Server;

    function hello($name) {
        return 'Hello ' . $name;
    }

    $server = new Server('tcp://0.0.0.0:2016');
    $server->addFunction('hello');
    $server->start();

unix_server.php

<?php
    require_once "vendor/autoload.php";

    use Hprose\Swoole\Server;

    function hello($name) {
        return 'Hello ' . $name;
    }

    $server = new Server('unix:/tmp/my.sock');
    $server->addFunction('hello');
    $server->start();

websocket_server.php

<?php
    require_once "vendor/autoload.php";

    use Hprose\Swoole\Server;

    function hello($name) {
        return 'Hello ' . $name;
    }

    $server = new Server('ws://0.0.0.0:8000/');
    $server->addFunction('hello');
    $server->start();

The websocket server is also a http server.

Client

Then you can create a hprose client to invoke it like this:

http_client.php

<?php
    require_once "vendor/autoload.php";

    use Hprose\Swoole\Client;

    $client = new Client('http://127.0.0.1/');
    $client->hello('World')->then(function($result) {
        echo $result;
    }, function($e) {
        echo $e;
    });
    $client->hello('World 0', function() {
        echo "ok\r\n";
    });
    $client->hello('World 1', function($result) {
        echo $result . "\r\n";
    });
    $client->hello('World 2', function($result, $args) {
        echo $result . "\r\n";
    });
    $client->hello('World 3', function($result, $args, $error) {
        echo $result . "\r\n";
    });

tcp_client.php

<?php
    require_once "vendor/autoload.php";

    use Hprose\Swoole\Client;

    $client = new Client('tcp://127.0.0.1:2016');
    $client->hello('World')->then(function($result) {
        echo $result;
    }, function($e) {
        echo $e;
    });
    $client->hello('World 0', function() {
        echo "ok\r\n";
    });
    $client->hello('World 1', function($result) {
        echo $result . "\r\n";
    });
    $client->hello('World 2', function($result, $args) {
        echo $result . "\r\n";
    });
    $client->hello('World 3', function($result, $args, $error) {
        echo $result . "\r\n";
    });

The result of invoking is a promise object, you can also specify the callback function after the arguments, the callback function supports 0 - 3 parameters:

params comments
result The result is the server returned, if no result, its value is null.
arguments It is an array of arguments. if no argument, it is an empty array.
error It is an object of Exception, if no error, its value is null.

More Repositories

1

hprose-php

Hprose is a cross-language RPC. This project is Hprose 3.0 for PHP
PHP
1,972
star
2

hprose-golang

Hprose is a cross-language RPC. This project is Hprose for Golang.
Go
1,247
star
3

hprose-java

Hprose is a cross-language RPC. This project is Hprose 2.0 for Java
Java
551
star
4

hprose-dotnet

Hprose 3.0 for .NET
C#
382
star
5

hprose

HPROSE is short for High Performance Remote Object Service Engine. It's a serialize and RPC library, the serialize library of hprose is faster, smaller and more powerful than msgpack, the RPC library is faster, easier and more powerful than thrift.
368
star
6

hprose-nodejs

Hprose is a cross-language RPC. This project is Hprose 2.0 for Node.js
JavaScript
301
star
7

hprose-html5

Hprose is a cross-language RPC. This project is Hprose 2.0 Client for HTML5
JavaScript
238
star
8

hprose-go

Hprose 1.0 for Golang (Deprecated). Hprose 2.0 for Golang is here:
Go
140
star
9

hprose-js

Hprose is a cross-language RPC. This project is Hprose 2.0 RPC for JavaScript
JavaScript
135
star
10

hprose-objc

Hprose is a cross-language RPC. This project is Hprose 2.0 Client for Objective-C
Objective-C
130
star
11

hprose-delphi

Hprose is a cross-language RPC. This project is Hprose 2.0 for Delphi and FreePascal
Pascal
116
star
12

hprose-wx

hprose 的微信小程序专用版
JavaScript
70
star
13

hprose-typescript

Hprose 3.0 for TypeScript
TypeScript
58
star
14

hprose-pecl

Hprose is a cross-language RPC. This project is Hprose serialize/unserialize extension for PHP
C
54
star
15

hprose-cpp

Hprose for C++
C++
51
star
16

hprose-python

Hprose for Python
Python
48
star
17

hprose-cpp1x

Hprose 2.0 for C++ 1x
C++
44
star
18

hprose-aauto

Hprose for AAuto Quicker
36
star
19

hprose-yii

Hprose Server for Yii
CSS
35
star
20

hprose-doc

Hprose 文档汇总
34
star
21

hprose-lua

Hprose for Lua
Lua
32
star
22

hprose-dart

Hprose 3.0 for Dart
Dart
30
star
23

hprose-d

Hprose for Dlang
D
26
star
24

hprose-workerman

A PHP class that enables you to use Hprose with Workerman. Includes custom protocol, bridge and interface. Enjoy Hprose at its finest with multi-process powers!
PHP
23
star
25

hprose-ruby

Hprose for Ruby
Ruby
22
star
26

hprose-rust

Hprose for Rust
Rust
21
star
27

hprose-swift

Hprose for Swift
18
star
28

hprose-as3

Hprose for ActionScript 3.0
ActionScript
18
star
29

hprose-phpcpp

Hprose for PHP-CPP (Deprecated)
C++
17
star
30

hprose-asp

Hprose for ASP
JavaScript
16
star
31

hprose-perl

Hprose for Perl
Perl
12
star
32

hprose-nim

Hprose for Nim
Nim
11
star
33

hprose-symfony

Hprose Server for Symfony
PHP
9
star
34

hprose-as2

Hprose for ActionScript 2.0
ActionScript
9
star
35

hprose-crystal

Hprose for Crystal
8
star
36

hprose-psr7

Hprose Service for PSR7
PHP
7
star
37

hprose-hack

Hprose for Hack
Hack
7
star
38

hprose-j2me

Hprose for Java ME
Java
7
star
39

hprose.github.io

Hprose WebSite
PHP
7
star
40

hprose-julia

Hprose for Julia
6
star
41

hprose-elixir

Hprose for Elixir
5
star