tourze / proxy-protocol-core
ProxyProtocol核心定义
0.0.2
2025-04-16 13:50 UTC
Requires
- php: ^8.1
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-04-25 19:07:54 UTC
README
A PHP core library for parsing and generating Proxy Protocol. Supports both V1 (text format) and V2 (binary format) versions of the protocol with basic data structures and parsing capabilities.
Features
- Support for Proxy Protocol V1 (text format) and V2 (binary format)
- Enum types for safer protocol constant usage
- Complete type hints and detailed documentation
- PSR standard compliant
Installation
composer require tourze/proxy-protocol-core
Usage
Proxy Protocol V1
use Tourze\ProxyProtocol\Enum\Version; use Tourze\ProxyProtocol\Model\Address; use Tourze\ProxyProtocol\Model\V1Header; // Create a V1 header $header = new V1Header(); $header->setVersion(Version::V1); $header->setProtocol('TCP4'); $header->setSourceAddress(new Address('192.168.1.1', 12345)); $header->setTargetAddress(new Address('192.168.1.2', 80));
Proxy Protocol V2
use Tourze\ProxyProtocol\Enum\AddressFamily; use Tourze\ProxyProtocol\Enum\Command; use Tourze\ProxyProtocol\Enum\Version; use Tourze\ProxyProtocol\Model\V2Header; // Create a V2 header $header = new V2Header(); $header->setVersion(Version::V2); $header->setCommand(Command::PROXY); $header->setAddressFamily(AddressFamily::TCP4); $header->setSourceAddress('192.168.1.1'); $header->setSourcePort(12345); $header->setTargetAddress('192.168.1.2'); $header->setTargetPort(80); // Parse a V2 header $data = "..."; // Binary data containing Proxy Protocol V2 header $header = V2Header::parseHeader($data);