# `php-http2` ## Installation Install with composer: ```bash $ composer require joopschilder/php-http2 ``` ## What is this? A `curl` wrapper for PHP that uses `HTTP/2` to send requests over a single TCP connection. Provided are: - The main class `JoopSchilder\Http2\Http2` - A simple class for requests supporting `curl` options - A simple class for responses ## What is this not? A production-ready library. I mean, you _are_ of course allowed to use it if you think it's useful. ## Example There is some example code in `bin/app.php`. In it's most basic form, usage of this library might look like this: ```php use JoopSchilder\Http2\Http2; use JoopSchilder\Http2\Response; $http2 = new Http2(); // Might also be an implementation of the ResponseHandler interface $http2->onResponse(function(Response $response) { var_dump($response); }); // This creates a request with sensible defaults $request = $http2->createRequest('https://www.twitter.com/'); $request->setOptions([CURLOPT_USERAGENT => 'AppleTV6,2/11.1']); $http2->addRequest($request); // Requests are not executed until this method is called $http2->execute(); ``` It's a good idea to use a different instance of `Http2` for every host you plan to make a request to. ## What's next? - Add more control to dynamically add requests to an `Http2` instance - Make an `Http2` instance coupled to a domain (as this is its intended use) - Use [`PSR-7`](https://www.php-fig.org/psr/psr-7/) HTTP message interfaces - Add a factory for requests