phonetworks/pho-server-rest 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phonetworks/pho-server-rest

Composer 安装命令:

composer require phonetworks/pho-server-rest

包简介

A REST based management API for the Pho Kernel.

README 文档

README

pho-server-rest

An event-driven non-blocking REST API for the Phở Kernel.

Pho-Server-Rest does not rely on a third party HTTP Server such as NGINX or Apache HTTPD. But it is recommended that you run it behind a proxy server for static assets and caching.

Requirements

Installation

The recommended way to install pho-server-rest is through git. MacOS and most UNIX operating system come with git equipped.

git clone https://github.com/phonetworks/pho-server-rest/

If you are on Windows or don't have git preinstalled, you may download and install git from https://git-scm.com/, or just download the pho-server-rest zip tarball from https://github.com/phonetworks/pho-server-rest/archive/master.zip and extract.

Once the REST Server is installed, you need a Phở Kernel to run it. You can install the standard Phở Kernel simply by typing:

git submodule init
git submodule update

Alternatively you may create your own kernel with a custom recipe, and copy/paste it under the kernel directory. For instructions on how to create a custom kernel, check out the README.md file of pho-kernel.

Once the kernel is set up, you should install the dependencies using Composer as follows:

composer install

Do not forget to install such dependencies for the submodule kernel as well. You would need to copy the composer.json from one of the presets which determine the structure of the graph you are to build.

cd kernel
cp presets/basic ./composer.json # any preset is fine
composer install
cd ..

To run the server, you must execute the run.php file. Alternatively, you may call the server programmatically:

<?php
require "vendor/autoload.php";
include("PATH/TO/YOUR/KERNEL");
$server = new \Pho\Server\Rest\Server($kernel);
$server->port(8080);
$server->serve();

Usage

<?php

/**
 * Returns the routes object to manipulate the behaviour of the server
 * @return self
 */
$server->routes();

/**
 * Returns all existing routes
 * @return self
 */
$server->routes()->all();

/**
 * Adds a new route:
 * @param string $method HTTP Method, like GET, PUT, DELETE
 * @param string $path HTTP Path like /some_path
 * @param callable $func Function to call with arguments; $request (\Psr\Http\Message\ServerRequestInterface), $response (\React\Http\Response)
 * @return void
 */
$server->routes()->add("GET", "/path/{arg:[0-9]+}", function($request, $response, $arg) {

});

/**
 * Select no route
 * @return self
 */
$server->routes()->none()

/**
 * Select all routes, minus the defined ones.
 * @return self
 */
$server->routes()->all()->but(...)

/**
 * Select only the defined ones.
 */
$server->routes()->only(...)

/**
 * Only admins can access the selected routes
 * The opposite is: `unlock()`
 * @return void
 */
$server->routes()->only(...)->lock()

/**
 * No one can access the selected routes
 * The opposite is: `enable()`
 * @return void
 */
$server->routes()->only(...)->disable()

Sessions

<?php

Session::depend();
Session::destroy();
Session::begin();

Unit Testing

In order to run tests, make sure the REST server is running. For that, you'll need to type in php run.php while in the root folder, ensuring the kernel submodule was initialized and set up with the right recipe, and environment variables are properly entered.

Once the server is up and running, you may run the unit tests by typing vendor/bin/phpunit, assuming that you have already installed the dependencies.

FAQ

How do I change the port?

By default, pho-server-rest is designed to serve through port 1337. You may change it from the file run.php by changing the line that corresponds to $server->port(1337);

How can I use Pho Server as part of a real-time application?

Phở Server uses React's core reactor event loop, and can work with any application that uses the same infrastructure. To achieve that, one has to construct the Phở server object with the custom event loop as the second argument; $server = new \Pho\Server\Rest\Server($kernel, $custom_loop);

Once the server object is initialized, you can start the event loop separately using the serve() call by passing the false argument as follows: $server->serve(false);. This starts the server in a non-blocking way, so you can initialize the loop at a different point and time of your application's lifetime.

License

MIT, see LICENSE.

phonetworks/pho-server-rest 适用场景与选型建议

phonetworks/pho-server-rest 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.43k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 08 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「rest」 「api」 「server」 「graph」 「react」 「reactphp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 phonetworks/pho-server-rest 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 phonetworks/pho-server-rest 我们能提供哪些服务?
定制开发 / 二次开发

基于 phonetworks/pho-server-rest 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.43k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 8
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-24