Download the PHP package swover/swover without Composer

On this page you can find all versions of the php package swover/swover. 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 swover

Swover

Swover是一个基于Swoole扩展的服务类库,提供基础的HTTP、TCP、Process服务能力,不包含任何业务代码,只需简单配置即可安全使用,对业务代码完全无侵入。

依赖

虽然提供了对 PHP5 及 swoole 1.x 的支持,但仍建议升级到最新版。

安装

添加swover到composer.json文件,然后更新composer。

配置项

配置 类型 场景 必填 默认 描述
server_type string all Y 服务类型,可选项:http,tcp,process
daemonize bool all N false 服务是否以守护进程方式运行
process_name string all N server 服务的进程名,单节点内应唯一
worker_num int all N 1 worker 进程数
task_worker_num int tcp,http N 0 task-worker 进程数
host string tcp,http N 0.0.0.0 监听地址
port int tcp,http N 0 监听端口,0表示随机获取一个可用端口
max_request int all N 0 进程最大执行次数,超过时安全重启。0表示永不重启,为避免内存泄漏,建议设置
entrance string all Y 业务逻辑的入口,必须是可被调用的函数或方法,接收request返回response
async bool tcp,http N false 是否异步执行,如果为true,接收到请求后,转发给task异步处理
setting array all N 配置选项
events array all N 事件注册,支持二维数组,数组下标无实际作用。事件

开始使用

服务类型

Swover提供了三种服务类型可用:

通过服务启动时传入的server_type配置项决定服务类型。

启停服务

服务启动后,通过Request接收客户端请求,将Request对象作为参数传递给入口函数。

入口函数处理完业务逻辑后返回结果,建议返回Response对象、字符串或布尔值。

Request

服务接收到客户端数据后,构造\Swover\Utils\Request对象,构造函数接收参数为:

对象继承自\ArrayObject,可通过$request['get']$request->get$request->get()获取请求参数。

由于Process服务只是通过while(true)调用入口函数,所以传递给入口函数的是一个空的Request对象。

Response

入口函数完成后返回数据,构造\Swover\Utils\Response对象,响应结果到客户端,数据类型:

Response 实现:

业务入口:

Process服务中,当status大于400时,判定终止此次循环,将重启worker进程。

Event

提供了事件机制,可以通过服务启动前传入配置 或 调用\Swover\Utils\Events注册事件。

此处提供的事件,主要是为了扩展Swoole的事件回调,事件按照注册顺序先后触发,可使用Event::before()方法将方法插入队头。

注册的回调方法:

RequestResponse两个事件为特殊定义,其余事件的参数均须与Swoole事件严格一致。

支持的事件类型定义在\Swover\Contracts\Events接口中,建议绑定事件时直接使用预定义常量,避免触发失败。

事件类型大小写不敏感,最终绑定均转为小写。

TCP的receive和HTTP的request事件统一为request事件,参数及使用定义在\Swover\Utils\Event\Request

response事件参数及使用定义在\Swover\Utils\Event\Response

Worker

提供获取当前进程状态、主进程状态的方法。

父进程收到SIGCHLD信号后,子进程调用Worker::getStatus()时,会触发pcntl_signal_dispatch()注册的事件,将当前进程状态设置为false

利用此特性,在业务内判断当前进程的状态是否需要退出。

Worker::checkProcess($pid)用来检测指定进程ID是否正常存活,可用于在子进程中检测父进程的状态,当父进程不存在时退出当前进程。

示例


All versions of swover with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6
ext-swoole Version >=1.9.5
ext-pcntl Version *
ext-posix Version *
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 swover/swover contains the following files

Loading the files please wait ....