torres-developer/reverse-proxy
Composer 安装命令:
composer require torres-developer/reverse-proxy
包简介
Reverse Proxy using only PHP
关键字:
README 文档
README
A reverse proxy with PHP.
Why?
My school gives to the students access to a server.
We can serve static files and PHP it's also supported. That is why this is in PHP.
Let's say I created an HTTP server at localhost port 3000 (with PHP, node.js, ...). I can't make people able to access it over the internet because I don't have privileges to change the Apache server config or whatever to create a reverse proxy.
I'm trying to use the tools that were given to me :)
Examples
The simplest use
It will reverse proxy to http://localhost:3000/ always.
<?php declare(encoding="UTF-8"); declare(strict_types=1); use function TorresDeveloper\ReverseProxy\reverse_proxy; require __DIR__ . "/vendor/autoload.php"; reverse_proxy("http://localhost:3000/");
Other Example
In this example in contrary to the other one the request does not always go to
http://localhost:3000/. You need to make a request to the path /app/ and
then what appears after the /app/ will also be part of the request path that
the reverse proxy request so a request to /app/something/ will do a request
to http://localhost:3000/something/.
I'm also showing how you can handle some \Exceptions and the use off the
function respond to show respond the status code, headers, body, to the
client.
<?php declare(encoding="UTF-8"); declare(strict_types=1); use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Client\RequestExceptionInterface; use TorresDeveloper\HTTPMessage\Response; use TorresDeveloper\HTTPMessage\URI; use TorresDeveloper\ReverseProxy\ReverseProxy; use function TorresDeveloper\ReverseProxy\respond; use function TorresDeveloper\ReverseProxy\serverRequest; require __DIR__ . "/vendor/autoload.php"; $proxy = new ReverseProxy("/app/", new URI("http://localhost:3000/")); try { $res = $proxy->sendRequest(serverRequest()); } catch (RequestExceptionInterface $e) { $method = $e->getRequest()->getMethod(); $uri = $e->getRequest()->getUri(); respond(new Response( 500, body: "Request `[$method] $uri` failed.", headers: [ "Content-Type" => "text/plain" ] )); } catch (NetworkExceptionInterface $e) { $method = $e->getRequest()->getMethod(); $uri = $e->getRequest()->getUri(); respond(new Response( 500, body: "Request `[$method] $uri` could not be completed because of network issues.", headers: [ "Content-Type" => "text/plain" ] )); } catch (ClientExceptionInterface $e) { respond(new Response( 500, body: "Unexpected error occured on the reverse proxy side.", headers: [ "Content-Type" => "text/plain" ] )); } catch (\Throwable $th) { respond(new Response( 500, body: "Unexpected error occured.", headers: [ "Content-Type" => "text/plain" ] )); } if ($res->getStatusCode() === 404) { // It might be that the request to possibly reverse proxy didn't start with // the path of the endpoint defined on the ReverseProxy::__constructor // earlier in the code. } respond($res); exit(0);
torres-developer/reverse-proxy 适用场景与选型建议
torres-developer/reverse-proxy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「reverse proxy」 「psr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 torres-developer/reverse-proxy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 torres-developer/reverse-proxy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 torres-developer/reverse-proxy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Lazy loading for middleware and request handlers
Simple PSR-16 cache implementations for WordPress transient the OOP way
The TYPO3 Cloudflare Extension simplifies cache management, offering an efficient solution for TYPO3 administrators and developers. Seamlessly integrating with Cloudflare, a global leader in web performance and security, this extension provides advanced features to optimize, secure, and structure yo
a one to one and one to many reverse relation for laravel
Nominatim Geocoding API Client
Laravel integration for Nominatim Geocoding API Client
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: AGPL-3.0-or-later
- 更新时间: 2023-04-21