2017 © Pedro Peláez
 

library hessian-php

HessianPHP 2

image

tomato/hessian-php

HessianPHP 2

  • Friday, December 2, 2016
  • by tomato
  • Repository
  • 1 Watchers
  • 2 Stars
  • 56 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 6 % Grown

The README.md

HessianPHP 2

HessianPHP 2 is a library that implements the Hessian binary web services protocol for PHP 5., (*1)

The Hessian binary web service protocol makes web services usable without requiring a large framework, and without learning yet another alphabet soup of protocols. Because it is a binary protocol, it is well-suited to sending binary data without any need to extend the protocol with attachments., (*2)

Hessian was created by Caucho Technology in the Java programming language. This protocol was designed to be fast and simple to learn and use. It uses HTTP as transport by sending and receiving POST requests to remote services., (*3)

HessianPHP 2 is a complete rewrite of the original HessianPHP library published a few years ago to make it compatible with the newest versions of the protocol and PHP., (*4)

Installation

composer require tomato/hessian-php

Features

  • PHP 5 only
  • Hessian protocol version 1 and 2 with autodetection
  • Can create both clients and servers
  • Support CURL and standard http stream wrappers

Quick Start

Consuming a Hessian web service

To start consuming remote Hessian web services all you need to do is:, (*5)

  1. Create a HessianClient object passing the url of the service and additional options if required
  2. Call methods

This is an example code that creates a proxy to a remote service, calls several methods and prints the results:, (*6)

$testUrl = 'http://localhost/mathService.php';
$proxy = new HessianClient($testUrl);
try {
    echo $proxy->div(2, 5); 
} catch (Exception $e) {
   // ...handle error
}

Creating a Hessian web service

You have to create a script in the web server following this steps:, (*7)

  1. Create a HessianService wrapper object
  2. Register a previously created or new object in the service constructur or by calling registerObject().
  3. Execute the handle() method.

Thus, for example, if we want to publish a calculator service that is compatible with the previous example, we have to create a class something like this:, (*8)

class Math {
  function add($n1,$n2) {
    return $n1+$n2;
  }    
  function sub($n1,$n2) {
    return $n1-$n2;
  }    
  function mul($n1,$n2) {
    return $n1*$n2;
  }    
  function div($n1,$n2) {
    return $n1/$n2;
  }
}

Then create the service wrapper and register a Math object to make it accesible through Hessian:, (*9)

$service = new HessianService(new Math());
$service->handle();

That's it. Now we have successfully published a Hessian web service from a common PHP object. The url of the service is the same url of the script., (*10)

If you try to access the url using a web browser, you will get a 500 error because Hessian requires POST to operate., (*11)

Status

This is a dev master version. It's compatible with PHP 5.3. Deployment requires a little over 100KB., (*12)

HessianPHP is licensed under the MIT license, so you can comfortably use it in commercial applications., (*13)

The Versions

02/12 2016

dev-master

9999999-dev

HessianPHP 2

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by luyh