Skip to content

dulumao/hprose-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hprose for PHP



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.

Installation

Download Source Code

Download Link

install by composer

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

Usage

Server

Hprose for PHP is very easy to use. You can create a hprose server like this:

<?php
    require_once('Hprose.php');

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

    $server = new HproseHttpServer();
    $server->addFunction('hello');
    $server->start();

You can also use HproseSwooleHttpServer to create a standalone hprose server:

server.php

<?php
    require_once("Hprose.php");

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

    $server = new HproseSwooleHttpServer('0.0.0.0', 8080);
    $server->addFunction('hello');
    $server->start();

then use command line to start it:

php server.php

To use HproseSwooleHttpServer, you need install swoole first. The minimum version of swoole been supported is 1.7.11.

Client

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

<?php
    require_once("Hprose.php");
    $client = new HproseHttpClient('http://127.0.0.1/server.php');
    echo $client->hello('World');

Exception Handling

If an error occurred on the server, or your service function/method throw an exception. it will be sent to the client, and the client will throw it as an exception. You can use the try statement to catch it.

About

Hprose for PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%