承接 phprivoxy/proxy 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

phprivoxy/proxy

最新稳定版本:v0.8.10

Composer 安装命令:

composer require phprivoxy/proxy

包简介

Core library for HTTP/HTTPS proxy building.

README 文档

README

Core library for HTTP/HTTPS proxy building.

This PHP package based on Workerman framework (https://github.com/walkor/workerman) and will be useful for custom proxy servers creation.

Requirements

  • PHP >= 8.1

Installation

Using composer (recommended)

composer create phprivoxy/proxy

Simple transparent proxy sample

$handler = new PHPrivoxy\Proxy\Transparent();
new PHPrivoxy\Core\Server($handler);// By default, it listen all connections on 8080 port.

Configure your browser to work through a proxy server with the IP address 127.0.0.1 and port 8080.

Try to open any site on HTTP or HTTPS protocols. As sample, try to open https://php.net, https://google.com, https://microsoft.com.

This sample you also may find at "tests" directory.

Just run it:

php tests/transparent.php start

Simple SSL MITM (Man In The Middle) proxy sample

use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

class HttpClientMiddleware implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $client = new GuzzleHttp\Client();
        try {
            $response = $client->send($request, ['allow_redirects' => false]);
        } catch (GuzzleHttp\Exception\ConnectException $e) {
            // Do something
        } catch (GuzzleHttp\Exception\BadResponseException $e) {
            return $e->getResponse();
        }

        return $response;
    }
}

$httpClientMiddleware = new HttpClientMiddleware();
$queue = [$httpClientMiddleware];
$psr15handler = new Relay\Relay($queue);
$tcpHandler = new PHPrivoxy\Proxy\MITM($psr15handler);
$processes = 6; // Default 1.

new PHPrivoxy\Core\Server($tcpHandler, $processes);// By default, it listen all connections on 8080 port.

This sample you also may find at "tests" directory.

Just run it:

php tests/mitm.php start

On first run it create a self-signed SSL root certificate in CA subdirectory. Add this self-signed CA certificate in your browser trusted certificates!

For each site PHPrivoxy\Proxy\MITM will generate self-signed certificate in "certificates" subdirectory.

In this sample, we use simple PSR-15 compatible HttpClientMiddleware for site downloading. You also may add your own PSR-15 compatible Middlewares in queue for PSR-15 handler (modified Relay\Relay in this sample).

License

MIT License See LICENSE

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-26