1. Go to this page and download the library: Download belisoful/prado-http2 library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
belisoful / prado-http2 example snippets
use Prado\IO\Http2\TH2Session;
use Prado\IO\Http2\TNgHttp2;
$session = new TH2Session(true); // server side
$session->submitSettings([
TNgHttp2::SETTINGS_ENABLE_CONNECT_PROTOCOL => 1, // RFC 8441 (optional)
]);
$session->attachEventHandler('onRequest', function ($session, $stream) {
// $stream->getHeaders() sion->attachEventHandler('onClose', function ($session, $stream) {
// stream finished
});
// Pump a transport: feed what you read, write what it produces.
$transport->write($session->send()); // initial SETTINGS
while (/* connection open */) {
$session->receive($transport->read(65536)); // drives the events above
$transport->write($session->send());
}
$session = new TH2Session(false); // client side
$session->submitSettings([]);
$session->attachEventHandler('onResponse', function ($session, $stream) {
$status = $stream->getHeader(':status'); // the final (non-1xx) response
});
$session->attachEventHandler('onInformationalResponse', function ($session, $stream) {
// a 1xx response (100 Continue, 103 Early Hints) before the final response
});
$session->attachEventHandler('onTrailers', function ($session, $stream) {
// a trailing header block after the body (e.g. grpc-status)
});
$session->attachEventHandler('onData', function ($session, $stream) {
$body = $stream->getContents();
});
$stream = $session->request([
':method' => 'GET',
':scheme' => 'https',
':authority' => 'example.com',
':path' => '/',
]);
$stream->markLocalClosed(); // a GET has no body — end the request
$transport->write($session->send()); // preface + SETTINGS + request
$session->receive($transport->read(65536));