Download the PHP package masakielastic/llhttp without Composer
On this page you can find all versions of the php package masakielastic/llhttp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download masakielastic/llhttp
More information about masakielastic/llhttp
Files in masakielastic/llhttp
Package llhttp
Short Description PHP extension for llhttp - high-performance HTTP parser
License MIT
Informations about the package llhttp
PHP llhttp Extension
A PHP extension that provides high-performance HTTP parsing using the llhttp C library. This extension offers a simple, direct API for parsing HTTP requests and responses with excellent performance.
Features
- High Performance: Built on the fast llhttp C library used by Node.js
- Simple API: Clean, direct method calls without complex event systems
- Object-Oriented: Modern PHP interface with intuitive methods
- Request & Response Parsing: Support for both HTTP requests and responses
- Built-in Data Collection: Automatic header, URL, and body collection
- Memory Efficient: Streaming parser that handles large HTTP messages
- State Management: Reset and reuse parsers efficiently
Installation
Requirements
- PHP 8.0 or higher
- PHP development headers (
php-devpackage) - C compiler (gcc/clang)
- autotools (autoconf, automake, libtool)
Install with PIE
PIE (PHP Installer for Extensions) is the recommended installation method.
Build from Source
Usage
Basic HTTP Request Parsing
HTTP Response Parsing
Streaming Parsing
Auto-Detection with TYPE_BOTH
Parser State Management
API Reference
Parser Class
Constructor
new Parser(int $type)- Create a new parserParser::TYPE_BOTH- Auto-detect request or response (flexible parsing)Parser::TYPE_REQUEST- Parse HTTP requests onlyParser::TYPE_RESPONSE- Parse HTTP responses only
Parsing Methods
parse(string $data): void- Parse HTTP data chunkparseComplete(): void- Signal end of data (optional)reset(): void- Reset parser state for reuse
HTTP Information Methods
getHttpMajor(): int- Get HTTP major versiongetHttpMinor(): int- Get HTTP minor versiongetMethod(): int- Get HTTP method code (for requests)getMethodName(): string- Get HTTP method name (for requests)getStatusCode(): int- Get status code (for responses)getUrl(): string- Get request URL (for requests)shouldKeepAlive(): bool- Check if connection should be kept alivemessageNeedsEof(): bool- Check if message needs EOF
Data Access Methods
getHeaders(): array- Get all parsed headers as arraygetHeader(string $name): ?string- Get specific header value (case-insensitive)getBody(): string- Get request/response body
State Methods
isComplete(): bool- Check if parsing is completegetState(): int- Get current parser stateParser::STATE_INIT- Initial stateParser::STATE_PARSING- Currently parsingParser::STATE_COMPLETE- Parsing completeParser::STATE_ERROR- Error occurred
ErrorCodes Class
HTTP parsing error constants (see llhttp documentation for complete list).
Exception Handling
Testing
Run the test suite:
Performance
This extension leverages the llhttp C library for maximum performance:
- Zero-copy parsing where possible
- Minimal memory allocations
- Optimized state machine implementation
- Direct C integration without FFI overhead
- Used in production by Node.js
Architecture
The extension follows a streamlined, object-oriented design:
- Direct Method Calls: Simple, intuitive API without complex event systems
- Automatic Data Collection: Headers, URL, and body are collected automatically
- State Management: Clean state tracking with reset/reuse capability
- Memory Efficient: Proper cleanup and efficient string handling
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- llhttp - The underlying HTTP parser
-
PHP Extension Development documentation
- [ ] Add arginfo declarations for better reflection support
- [ ] Performance benchmarks vs other PHP HTTP parsers
- [ ] Additional utility methods for URL parsing
- [ ] Enhanced duplicate header handling
- [ ] Package for PECL distribution
- [ ] Comprehensive documentation and examples