frdl / proxy
PHP 代理脚本
v0.1.8
2024-09-01 20:22 UTC
Requires
Requires (Dev)
- webfan3/hps: *
README
基于 Guzzle 的简单 PHP 代理。
安装
使用 Composer...
composer require frdl/proxy
...或者如果你想构建一个更大的项目,可以使用 Webfan 安装程序。
使用方法
<?php use frdl\Proxy\Proxy; require 'vendor/autoload.php'; $proxy = (new Proxy(null, $_SERVER['REQUEST_URI'], 'green.example.com', //target host $_SERVER['HTTP_HOST'], //User Input, forward optionaly* $_SERVER['REQUEST_METHOD'], 'https', false)) ->withFakeHost(true) //*Do overwrite/not use users host header //...or... ->withFakeHeader('X-Forwarded-Host') ; $proxy->handle(true);
内部代理会静默忽略 bounce
检测,以回退到任何本地脚本。你可以在处理 HTTP 转发之前/之后使用它,例如在相同的主机上执行(测试)请求。
<?php if(!$proxy->bounce()){ $proxy = (new Proxy('blue', $_SERVER['REQUEST_URI'], 'blue.example.com', //target host 'example.com', //set the host header on the target script $_SERVER['REQUEST_METHOD'], 'https', true)) ->handle(true); }
缓存
内置缓存功能
composer require doctrine/cache
$proxy->withCacheDir(string $dir = null, int $ttl= 1800, bool $force=true)