# hprose-php **Repository Path**: fbbin/hprose-php ## Basic Information - **Project Name**: hprose-php - **Description**: Hprose 全名是高性能远程对象服务引擎。 它是一个新型的轻量级跨语言跨平台面向对象的高性能远程动态通讯中间件。它不但易学易用,而且功能强大。本项目是 Hprose 的 PHP 版本实现。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: http://hprose.com - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 18 - **Created**: 2016-03-31 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Hprose for PHP [![Build Status](https://travis-ci.org/hprose/hprose-php.svg?branch=master)](https://travis-ci.org/hprose/hprose-php) [![Join the chat at https://gitter.im/hprose/hprose-php](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](https://gitter.im/hprose/hprose-php?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ![Supported PHP versions: 5.3 .. 7.0](https://img.shields.io/badge/php-5.3~7.0-blue.svg) [![Packagist](https://img.shields.io/packagist/v/hprose/hprose.svg)](https://packagist.org/packages/hprose/hprose) [![Packagist Download](https://img.shields.io/packagist/dm/hprose/hprose.svg)](https://packagist.org/packages/hprose/hprose) [![License](https://img.shields.io/packagist/l/hprose/hprose.svg)](https://packagist.org/packages/hprose/hprose) >--- - **[Introduction](#introduction)** - **[Usage](#usage)** - **[Server](#server)** - **[Client](#client)** - **[Exception Handling](#exception-handling)** >--- ## 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](https://github.com/hprose/hprose-php/archive/master.zip) ### install by `composer` ```javascript { "require": { "hprose/hprose": "dev-master" } } ``` ## Usage ### Server Hprose for PHP is very easy to use. You can create a hprose server like this: ```php addFunction('hello'); $server->start(); ``` You can also use `HproseSwooleServer` to create a standalone hprose server: `server.php` ```php addFunction('hello'); $server->start(); ``` then use command line to start it: `php server.php` To use `HproseSwooleServer`, you need install [swoole](http://www.swoole.com/) first. The minimum version of [swoole](https://github.com/swoole/swoole-src) been supported is 1.7.16. `HproseSwooleServer` not only support creating http server,but also support create tcp, unix and websocket server. For examples: `tcp_server.php` ```php addFunction('hello'); $server->start(); ``` `unix_server.php` ```php addFunction('hello'); $server->start(); ``` `websocket_server.php` ```php 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: ```php hello('World'); ``` Hprose also suplied `HproseSwooleClient`,it supports http,tcp and unix. For example: ```php hello('World'); ?> ``` It also support asynchronous concurrency invoke. For example: ```php hello('World', 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 callback function of asynchronous concurrency invoking 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. | ### 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. No exception throwed on asynchonous invoking. The exception object will be passed to the callback function as the third argument.