Execute HTTP/2 requests efficiently with curl
Go to file
2019-12-07 15:03:02 +01:00
bin Initial commit 2019-12-07 15:03:02 +01:00
src Initial commit 2019-12-07 15:03:02 +01:00
.gitignore Initial commit 2019-12-07 15:03:02 +01:00
composer.json Initial commit 2019-12-07 15:03:02 +01:00
composer.lock Initial commit 2019-12-07 15:03:02 +01:00
README.md Initial commit 2019-12-07 15:03:02 +01:00

curl-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:

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 HTTP message interfaces
  • Add a factory for requests