Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hprose/hprose-swoole
Hprose asynchronous client & standalone server based on swoole
https://github.com/hprose/hprose-swoole
Last synced: 7 days ago
JSON representation
Hprose asynchronous client & standalone server based on swoole
- Host: GitHub
- URL: https://github.com/hprose/hprose-swoole
- Owner: hprose
- License: mit
- Created: 2016-07-20T04:44:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-04T06:18:16.000Z (over 5 years ago)
- Last Synced: 2024-12-15T02:06:25.034Z (about 1 month ago)
- Language: PHP
- Homepage:
- Size: 67.4 KB
- Stars: 181
- Watchers: 23
- Forks: 41
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- favorite-link - Hprose 基于 swoole 的异步客户端和独立服务器。
- awesome-swoole - hprose-swoole - Hprose asynchronous client & standalone server based on swoole. (Server)
README
# Hprose for Swoole
[![Build Status](https://travis-ci.org/hprose/hprose-swoole.svg?branch=master)](https://travis-ci.org/hprose/hprose-swoole)
![Supported PHP versions: 5.3 .. 7.1](https://img.shields.io/badge/php-5.3~7.1-blue.svg)
[![Packagist](https://img.shields.io/packagist/v/hprose/hprose-swoole.svg)](https://packagist.org/packages/hprose/hprose-swoole)
[![Packagist Download](https://img.shields.io/packagist/dm/hprose/hprose-swoole.svg)](https://packagist.org/packages/hprose/hprose-swoole)
[![License](https://img.shields.io/packagist/l/hprose/hprose-swoole.svg)](https://packagist.org/packages/hprose/hprose-swoole)## 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](https://github.com/hprose/hprose-swoole/archive/master.zip)### install by `composer`
```javascript
{
"require": {
"hprose/hprose-swoole": "dev-master"
}
}
```## Usage
You need to install [swoole](http://www.swoole.com/) first. The minimum version of [swoole](https://github.com/swoole/swoole-src) been supported is 1.8.8.
You also need to install [hprose-pecl](https://pecl.php.net/package/hprose) 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
addFunction('hello');
$server->start();
````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:
`http_client.php`
```php
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
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. |