php-http2/bin/app.php

38 lines
1.2 KiB
PHP
Raw Normal View History

2019-12-07 15:03:02 +01:00
<?php
use JoopSchilder\Http2\Http2;
use JoopSchilder\Http2\Response;
require_once __DIR__ . '/../vendor/autoload.php';
$http2 = new Http2();
$http2->onResponse(function (Response $response) {
$statusLine = substr($response->getHeader(), 0, strpos($response->getHeader(), "\r"));
$statusLine = str_pad($statusLine, 14, ' ', STR_PAD_RIGHT);
print("$statusLine {$response->getOriginalUrl()}\n");
});
// Add urls
$urls = [
'https://twitter.com/survivetheark',
'https://twitter.com/missingpeople',
'https://twitter.com/elainecrowley',
'https://twitter.com/2020comms',
'https://twitter.com/goal',
'https://twitter.com/cydarmedical',
'https://twitter.com/cloakzy',
'https://twitter.com/cllrandrewkelly',
'https://twitter.com/youranonnews',
'https://twitter.com/trickyjabs',
];
foreach ($urls as $url) {
$http2->addRequest($http2->createRequest($url));
}
// Execute the requests
print("Note: it might take some time to establish the TCP connection.\n");
print("The benefits of HTTP/2 become more clear if you send more requests to the same server.\n\n");
$startTime = microtime(true);
$http2->execute();
printf("Requests: %d, time(s): %.3f\n", count($urls), microtime(true) - $startTime);