Download the PHP package xdapp/service-register without Composer

On this page you can find all versions of the php package xdapp/service-register. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package service-register

XDApp RPC Service SDK

XDAppRPC服务SDK

依赖

安装

首先需要安装composer,安装方式(see https://getcomposer.org/download/

在已有PHP项目中加入依赖包

在新项目中使用(HelloWorld,适合新手)

1.新建文件夹,创建 composer.json 文件,内容:

2.运行 composer install,稍等片刻即可安装好(若网络慢,可使用中国镜像,see https://pkg.phpcomposer.com/

3.创建一个文件夹,比如叫 service,然后创建一个 test.php 文件,内容:

4.创建 run.php 文件:

  1. 运行 php run.php

确保你的服务器时间准确并且线上环境需要需要支持SSL支持,执行 php --ri swoole 查看,有 openssl 表示ok,或执行 php -a 输入 echo SWOOLE_SSL; 有512数字表示OK

Dockerfile

更多使用方法

更多的使用方法see: https://github.com/hprose/hprose-php/wiki/06-Hprose-服务器

服务环境

区域 环境 使用方法
国服 生产环境 connectToProduce()
东南亚正式服 生产环境 connectToProduceAsia()
欧洲正式服 生产环境 connectToProduceEurope()
DEV测试环境 测试环境 connectToDev()
本地测试环境 测试环境 connectToLocalDev()

关于 context 上下文对象

在RPC请求时,如果需要获取到请求时的管理员ID等等参数,可以用此获取,如上面 hello 的例子,通过 $context = Service::getCurrentContext() 可获取到 context,包括:

参数 说明
service 当前服务
client 通信的连接对象,可以使用 close() 方法关闭连接
requestId 请求的ID
appId 请求的应用ID
serviceId 请求发起的服务ID,0表示XDApp系统请求,1表示来自浏览器的请求
adminId 请求的管理员ID,0表示系统请求
userdata 默认 stdClass 对象,可以自行设置参数

更多参数见 XDApp\ServiceReg\Context 对象

Service 常用方法如下:

connectToProduce()

连接到生产环境,将会创建一个异步tls连接接受和发送RPC数据,无需自行暴露端口,如果遇到网络问题和服务器断开可以自动重连,除非是因为密钥等问题导致的断开将不会重新连接

connectToDev($serviceKey = null)

同上,连接到研发环境, 不设置 serviceKey 则使用 new ServiceAgent 时传入的密钥

connectToLocalDev($host = '127.0.0.1', $port = 8061, $serviceKey = null)

同上,连接到本地研发服务器,请下载 XDApp-Local-Dev 本地开发工具,https://github.com/xdapp/xdapp-local-dev ,启动服务

addWebFunction($function, $alias = null, $option = [])

注册一个前端web页面可访问的RPC方法到服务上,它是 service.addFunction() 方法的封装,差别在于会自动对 alias 增加 serviceName 前缀

$service->addWebFunction(hello, 'hello') 相当于 $service->addFunction(hello, 'servicename_hello')

addFunction($function, $alias = null, $option = [])

注册一个RPC方法到服务上

addHttpApiProxy($url, $alias = 'api', $methods = ['get'], array $httpHeaders = [])

添加一个http代理

使用场景: 当服务器里提供一个内部Http接口,但是它没有暴露给外网也没有权限验证处理,但希望Web页面可以使用 此时可以使用此方法,将它暴露成为一个XDApp的RPC服务,在网页里直接通过RPC请求将数据转发到SDK请求后返回,不仅可以实现内网穿透功能还可以在Console后台设置访问权限。

每个Http代理请求都会带以下头信息,方便业务处理:

Vue页面使用

方法接受3个参数,$uri, $data, $timeout,其中 $data 只有在 post 和 put 有效,$timeout 默认 30 秒

addMissingFunction(function, $option = [])

此方法注册后,所有未知RPC请求都降调用它,它将传入2个参数,分别是RPC调用名称和参数

setVersion($ver)

设置服务器版本,在 Console 中的服务管理里可以看到,默认为 1.0

setLogger(callable $logger)

设置一个log处理方法,方法接受3个参数,分别是:

addFilter() / removeFilter() 过滤器

可以方便开发调试

see https://github.com/hprose/hprose-php/wiki/11-Hprose-过滤器

Sentry支持

首先需要安装 sentry : composer require sentry/sdk, 然后 XDApp\ServiceReg\Service::sentryInit('https://<key>@<organization>.ingest.sentry.io/<project>'); 即可

更多参数见 https://docs.sentry.io/error-reporting/configuration/?platform=php


All versions of service-register with dependencies

PHP Build Version
Package Version
Requires php Version ^7.0.0
ext-swoole Version >= 4.0
ext-snappy Version *
ext-hprose Version *
ext-mbstring Version *
hprose/hprose Version ~2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package xdapp/service-register contains the following files

Loading the files please wait ....