hprose/hprose-swoole
Composer 安装命令:
composer require hprose/hprose-swoole
包简介
Hprose asynchronous client & standalone server based on swoole
关键字:
README 文档
README
Hprose for 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
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. |
hprose/hprose-swoole 适用场景与选型建议
hprose/hprose-swoole 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29.22k 次下载、GitHub Stars 达 179, 最近一次更新时间为 2016 年 07 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「rpc」 「serialize」 「json」 「http」 「websocket」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hprose/hprose-swoole 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hprose/hprose-swoole 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hprose/hprose-swoole 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
LazyPDO is a set of wrappers over PHP's standard PDO and PDOStatement classes. It enables lazy loading, serialization and decoration.
Microservice RPC through message queues.
Transform data structures
Lightweight PHP library that allows exchanging binary data with Qt programs (QDataStream)
Runn Me! Serialization Library
统计信息
- 总下载量: 29.22k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 179
- 点击次数: 29
- 依赖项目数: 15
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-07-20