react/http
Event-driven, streaming HTTP client and server for ReactPHP. Send many concurrent async HTTP/HTTPS requests, handle redirects/timeouts/auth, and stream request/response bodies. Build plain HTTP or secure HTTPS servers on ReactPHP Socket and EventLoop.
Start by installing via Composer (composer require react/http) and include the autoloader. The Browser class is your primary entry point for making async HTTP requests, while HttpServer is used to build event-driven HTTP servers. Begin with the quickstart examples in the README: a simple client fetching a URL and a basic server returning "Hello World!". Use Browser::get(), post(), etc., for clients, and wire HttpServer with a SocketServer for serving requests. All methods return Promises, so use then() for handling responses or errors.
Use Browser with method chaining to configure clients (e.g., withTimeout(), withBase(), withFollowRedirects()). For servers, route requests by inspecting $request->getMethod() and $request->getUri()->getPath(), returning PSR-7 Response objects via static helpers like Response::json() or Response::html(). Implement middleware to decorate request handling (e.g., RequestBodyBufferMiddleware, custom logging or auth). Leverage streaming for large uploads/downloads: use requestStreaming() and ReadableStreamInterface/WritableStreamInterface for memory-efficient data pipelines. Combine LimitConcurrentRequestsMiddleware for rate limiting or StreamingRequestMiddleware for partial request body access.
1.x branch for production stability unless you’re testing early releases. Check release tags carefully.Connector.BlockingResponseStream in production; it’s only for CLI tools or scripts. Prefer async patterns throughout your stack.Transfer-Encoding: chunked unless Content-Length is explicitly set. Never assume Content-Length is present or accurate—validate or buffer if needed.RequestBodyParserMiddleware after buffering if you need parsed $_POST/php://input—but prefer direct stream access for async efficiency.Loop::get()->addTimer(0.1, ...), log request/response sizes, and use var_dump($response->getHeaders()) early to verify content types and status codes.How can I help you explore Laravel packages today?