定制 phprivoxy/core 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

phprivoxy/core

最新稳定版本:v0.10.4

Composer 安装命令:

composer require phprivoxy/core

包简介

Core library for TCP and HTTP connections handling.

README 文档

README

Core library for TCP connections handling.

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

Requirements

  • PHP >= 8.1

Installation

Using composer (recommended)

composer create phprivoxy/core

Simple TCP server sample

namespace PHPrivoxy\Core;

use Workerman\Connection\TcpConnection;

class HelloWorld implements PHPrivoxy\Core\Tcp\TcpHandlerInterface
{
    public function handle(TcpConnection $connection, ?ConnectionParameters $connectionParameters = null): void
    {
        $connection->send("HTTP/1.1 200 OK\r\ncontent-type: text/html;charset=UTF8\r\n\r\n" . 'Hello, world!');
        $connection->close();
    }
}

$handler = new HelloWorld();
new TcpServer($handler, 1, 8080, '0.0.0.0');

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

Just run it:

php tests/tcp_server.php start

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 protocol. As sample, try to open http://php.net, http://google.com, http://microsoft.com.

Try to open http://not-existing-site/ - it will work! :-)

Simple HTTP server sample

namespace PHPrivoxy\Core;

use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Workerman\Connection\TcpConnection;

class Psr7HelloWorld implements RequestHandlerInterface
{
    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        return new Workerman\Psr7\Response(200, ['content-type' => 'text/html'], 'Hello, world!');
    }
}

class ResponseHandler implements PHPrivoxy\Core\Http\ResponseHandlerInterface
{
    public function handle(ResponseInterface $response, TcpConnection $connection): void
    {
        $connection->send($response);
        $connection->close();
    }
}

$requestHandler = new Psr7HelloWorld();
$responseHandler = new ResponseHandler();
new HttpServer($requestHandler, $responseHandler, 1, 8080, '0.0.0.0');

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

Just run it:

php tests/http_server.php start

### License
MIT License See [LICENSE](LICENSE)

统计信息

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

GitHub 信息

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

其他信息

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