Share
Embed
[Edge 2016] HTTP/2 and Asynchronous APIs
HTTP/2 (H2) is coming, and along with it a whole new way of communicating over the web. Connection re-use, prioritization, multiplexing, and server push are just some of the features in H2.
In this talk we'll look at how to handle HTTP/2 Server Push programmatically, and how it can affect your application architecture.
Davey Shafik
October 19, 2016
Transcript
150 slides
-
H T T P/ 2 A N D A SY
N C H R O N O U S A P I S -
F E TC H I N G A B LO
G P O ST + CO M M E N TS CC-BY: John Trainor -
{ "type": "post", "id": "1", "title": "JSON API paints my
bikeshed!", "tags": ["json", "api", "relationships"], "author": "http://example.com/posts/1/author", "comments": "http://example.com/posts/1/comments" } -
{ "type": "post", "id": "1", "title": "JSON API paints my
bikeshed!", "tags": ["json", "api", "relationships"], "author": "http://example.com/posts/1/author", "comments": "http://example.com/posts/1/comments" } -
L E T ’ S M U LT I P
L E X ! -
M U LT I P L E X E D
Ȑ GET /post/example/comments/3 -
M U LT I P L E X E D
Ȑ GET /post/example/comments/3 GET /post/example/comments/1 -
M U LT I P L E X E D
Ȑ GET /post/example/comments/3 GET /post/example/comments/1 GET /post/example/comments/2 -
M U LT I P L E X E D
Ȑ GET /post/example/comments/3 GET /post/example/comments/1 GET /post/example/comments/2 200 OK application/json -
M U LT I P L E X E D
Ȑ GET /post/example/comments/3 GET /post/example/comments/1 GET /post/example/comments/2 200 OK application/json 200 OK application/json -
M U LT I P L E X E D
Ȑ GET /post/example/comments/3 GET /post/example/comments/1 GET /post/example/comments/2 200 OK application/json 200 OK application/json 200 OK application/json -
S T I L L M A K I N
G L O T S O F R E Q U E S T S -
{ "type": "post", "id": "1", "title": "JSON API paints my
bikeshed!", "tags": ["json", "api", "relationships"], "author": { "type": "author", "id": 1, "name": "Davey Shafik", "twitter": "@dshafik", "gravatar": "fee39f0c0ffb29d9ac21607ed188be6b" }, "comments": [ { "type": "comment", "id": "1", "content": "FIRST!", "author": { "type": "author", "id": 2, "name": "Jill Random", "gravatar": "706b16b2fb732ab6079a10fea61d078b" } }, { "type": "comment", "id": "2", "content": "second", "author": { "type": "author", "id": 3, "name": "John Person", "gravatar": "8e2279479945ca4778eb3cb8d88cda58" } }, { "type": "comment", "id": "3", "content": "third", "author": { "type": "author", "id": 1, "name": "Davey Shafik", "twitter": "@dshafik", "gravatar": "fee39f0c0ffb29d9ac21607ed188be6b" } }, { "type": "comment", "id": "4", "content": "fourth", "author": { "type": "author", "id": 2, "name": "Jill Random", "gravatar": "706b16b2fb732ab6079a10fea61d078b" } } ] } -
{ "type": "post", "id": "1", "title": "JSON API paints my
bikeshed!", "tags": ["json", "api", "relationships"], "author": { "type": "author", "id": 1, "name": "Davey Shafik", "twitter": "@dshafik", "gravatar": "fee39f0c0ffb29d9ac21607ed188be6b" }, "comments": [ { "type": "comment", "id": "1", -
{ "type": "post", "id": "1", "title": "JSON API paints my
bikeshed!", "tags": ["json", "api", "relationships"], "author": { "type": "author", "id": 1, "name": "Davey Shafik", "twitter": "@dshafik", "gravatar": "fee39f0c0ffb29d9ac21607ed188be6b" }, "comments": [ { "type": "comment", "id": "1", -
"gravatar": "fee39f0c0ffb29d9ac21607ed188be6b" }, "comments": [ { "type": "comment", "id": "1",
"content": "FIRST!", "author": { "type": "author", "id": 2, "name": "Jill Random", "gravatar": "706b16b2fb732ab6079a10fea61d078b" } }, { "type": "comment", "id": "2", -
} }, { "type": "comment", "id": "3", "content": "third", "author":
{ "type": "author", "id": 1, "name": "Davey Shafik", "twitter": "@dshafik", "gravatar": "fee39f0c0ffb29d9ac21607ed188be6b" } }, { "type": "comment", "id": "4", -
} }, { "type": "comment", "id": "3", "content": "third", "author":
{ "type": "author", "id": 1, "name": "Davey Shafik", "twitter": "@dshafik", "gravatar": "fee39f0c0ffb29d9ac21607ed188be6b" } }, { "type": "comment", "id": "4", -
} }, { "type": "comment", "id": "4", "content": "fourth", "author":
{ "type": "author", "id": 2, "name": "Jill Random", "gravatar": "706b16b2fb732ab6079a10fea61d078b" } } ] } -
S E R V E R P US H CC-BY:
Steven Depolo -
Ȑ GET /post/1/comment/2 GET /post/1/comment/3 GET /post/1/comment/4 GET /post/1/comment/1/author GET
/post/1/comment/2/author GET /post/1/comment/3/author GET /post/1/comment/4/author GET /post/1/comments GET /post/1/comment/1 -
Ȑ GET /post/1/comment/2 GET /post/1/comment/3 GET /post/1/comment/4 GET /post/1/comment/1/author GET
/post/1/comment/2/author GET /post/1/comment/3/author GET /post/1/comment/4/author GET /post/1/comment/1/author/avatar.png GET /post/1/comment/2/author/avatar.png GET /post/1/comment/3/author/avatar.png GET /post/1/comment/4/author/avatar.png GET /post/1/comments GET /post/1/comment/1 -
D E P E N D E N C I
E S CC-BY-SA 2.0: David Gamez -
A P I R E Q U E ST GET
/post/1 Ɇ ɂ Ȑ -
A P I R E Q U E ST GET
/post/1 200 OK application/json Ɇ ɂ Ȑ -
S U B - R E S O U R
C E P US H W I T H D E P E N D E N C I E S Ɇ Ȑ GET /post/1 200 OK application/json -
S U B - R E S O U R
C E P US H W I T H D E P E N D E N C I E S Ɇ Ȑ GET /post/1 200 OK application/json /post/1/comments /author/1 -
S U B - R E S O U R
C E P US H W I T H D E P E N D E N C I E S Ɇ Ȑ GET /post/1 200 OK application/json /post/1/comments /author/1 /comment/1 /comment/… -
S U B - R E S O U R
C E P US H W I T H D E P E N D E N C I E S Ɇ Ȑ GET /post/1 200 OK application/json /post/1/comments /author/1 /comment/1 /images/author/1 /comment/… -
S U B - R E S O U R
C E P US H W I T H D E P E N D E N C I E S Ɇ Ȑ GET /post/1 200 OK application/json /post/1/comments /author/1 /comment/1 /author/2 /images/author/1 /comment/… -
S U B - R E S O U R
C E P US H W I T H D E P E N D E N C I E S Ɇ Ȑ GET /post/1 200 OK application/json /post/1/comments /author/1 /comment/1 /author/2 /images/author/1 /comment/… /author/… -
$url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0; $i <= $numRequests;
$i++) { $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, $i); curl_setopt_array($ch, $opts); curl_exec($ch); curl_close($ch); } H T T P/ 1 . 1 : SY N C H R O N O US -
$url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0; $i <= $numRequests;
$i++) { $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, $i); curl_setopt_array($ch, $opts); curl_exec($ch); curl_close($ch); } H T T P/ 1 . 1 : SY N C H R O N O US -
$url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0; $i <= $numRequests;
$i++) { $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, $i); curl_setopt_array($ch, $opts); curl_exec($ch); curl_close($ch); } H T T P/ 1 . 1 : SY N C H R O N O US -
$url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0; $i <= $numRequests;
$i++) { $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, $i); curl_setopt_array($ch, $opts); curl_exec($ch); curl_close($ch); } H T T P/ 1 . 1 : SY N C H R O N O US -
$url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0; $i <= $numRequests;
$i++) { $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, $i); curl_setopt_array($ch, $opts); curl_exec($ch); curl_close($ch); } H T T P/ 1 . 1 : SY N C H R O N O US -
$url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0; $i <= $numRequests;
$i++) { $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, $i); curl_setopt_array($ch, $opts); curl_exec($ch); curl_close($ch); } H T T P/ 1 . 1 : SY N C H R O N O US -
4 7 . 6 7 s e co n
d s CC-BY: Hernán Piñera -
$url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0; $i <= $numRequests;
$i++) { $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, $i); curl_setopt_array($ch, $opts); curl_exec($ch); curl_close($ch); } H T T P/ 2 : SY N C H R O N O US -
$url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0; $i <= $numRequests;
$i++) { $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, $i); curl_setopt_array($ch, $opts); curl_exec($ch); curl_close($ch); } $opts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2; H T T P/ 2 : SY N C H R O N O US -
$url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0; $i <= $numRequests;
$i++) { $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, $i); curl_setopt_array($ch, $opts); curl_exec($ch); curl_close($ch); } H T T P/ 2 : SY N C H R O N O US -
$url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0; $i <= $numRequests;
$i++) { $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, $i); curl_setopt_array($ch, $opts); curl_exec($ch); curl_close($ch); } $opts[CURLOPT_HTTP_VERSION] = HTTP_VERSION_2_0; H T T P/ 2 : SY N C H R O N O US -
$url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0; $i <= $numRequests;
$i++) { $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, $i); curl_setopt_array($ch, $opts); curl_exec($ch); curl_close($ch); } H T T P/ 2 : SY N C H R O N O US -
$url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0; $i <= $numRequests;
$i++) { $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, $i); curl_setopt_array($ch, $opts); curl_exec($ch); curl_close($ch); } $opts[CURLOPT_HTTP_VERSION] = HTTP_VERSION_2_0; H T T P/ 2 : SY N C H R O N O US -
6 2 . 1 9 s e co n
d s CC-BY-NC: Scott Beckner -
$mh = curl_multi_init(); $url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0;
$i <= $numRequests; $i++) { $handles[] = $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, '%d'); curl_setopt_array($ch, $opts); curl_multi_add_handle($mh, $ch); } H T T P/ 1 . 1 : CO N CU R R E N T -
$mh = curl_multi_init(); $url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0;
$i <= $numRequests; $i++) { $handles[] = $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, '%d'); curl_setopt_array($ch, $opts); curl_multi_add_handle($mh, $ch); } H T T P/ 1 . 1 : CO N CU R R E N T -
$mh = curl_multi_init(); $url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0;
$i <= $numRequests; $i++) { $handles[] = $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, '%d'); curl_setopt_array($ch, $opts); curl_multi_add_handle($mh, $ch); } H T T P/ 1 . 1 : CO N CU R R E N T -
$mh = curl_multi_init(); $url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0;
$i <= $numRequests; $i++) { $handles[] = $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, '%d'); curl_setopt_array($ch, $opts); curl_multi_add_handle($mh, $ch); } H T T P/ 1 . 1 : CO N CU R R E N T -
H T T P/ 1 . 1 : CO N
CU R R E N T ( CO N T. ) do { $exec = curl_multi_exec($mh, $running); } while ($exec == CURLM_CALL_MULTI_PERFORM); while ($running && $exec == CURLM_OK) { $ready = curl_multi_select($mh); if ($ready != -1) { do { $exec = curl_multi_exec($mh, $running); } while ($exec == CURLM_CALL_MULTI_PERFORM); } } -
$url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0; $i <= $numRequests;
$i++) { $handles[] = $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, '%d'); curl_setopt_array($ch, $opts); curl_multi_add_handle($mh, $ch); } H T T P/ 2 : M U LT I P L E X E D $mh = curl_multi_init(); -
$url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0; $i <= $numRequests;
$i++) { $handles[] = $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, '%d'); curl_setopt_array($ch, $opts); curl_multi_add_handle($mh, $ch); } H T T P/ 2 : M U LT I P L E X E D $mh = curl_multi_init(); $opts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2; -
$opts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2; $url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0;
$i <= $numRequests; $i++) { $handles[] = $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, '%d'); curl_setopt_array($ch, $opts); curl_multi_add_handle($mh, $ch); } $mh = curl_multi_init(); curl_multi_setopt( $mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX ); -
$opts[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_2; $url = 'https://http2.akamai.com/demo/tile-%d.png'; for ($i = 0;
$i <= $numRequests; $i++) { $handles[] = $ch = curl_init(); $opts[CURLOPT_URL] = sprintf($url, '%d'); curl_setopt_array($ch, $opts); curl_multi_add_handle($mh, $ch); } $mh = curl_multi_init(); curl_multi_setopt( $mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX ); -
H T T P/ 2 : M U LT I
P L E X E D ( CO N T. ) do { $exec = curl_multi_exec($mh, $running); } while ($exec == CURLM_CALL_MULTI_PERFORM); while ($running && $exec == CURLM_OK) { $ready = curl_multi_select($mh); if ($ready != -1) { do { $exec = curl_multi_exec($mh, $running); } while ($exec == CURLM_CALL_MULTI_PERFORM); } } -
2 . 1 4 s e co n d
s CC-BY: motoracereports -
H A N D L I N G S E
R V E R P US H -
$transfers = 1; $cb = function( $parent, $pushed, $headers )
use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init(); curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX); curl_multi_setopt($mh, CURLMOPT_PUSHFUNCTION, $cb); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://localhost:8080/index.html"); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_multi_add_handle($mh, $ch); $active = null; do { $status = curl_multi_exec($mh, $active); -
$transfers = 1; $cb = function( $parent, $pushed, $headers )
use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init(); -
$transfers = 1; $cb = function( $parent, $pushed, $headers )
use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init(); -
$transfers = 1; $cb = function( $parent, $pushed, $headers )
use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init(); -
$transfers = 1; $cb = function( $parent, $pushed, $headers )
use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init(); -
$transfers = 1; $cb = function( $parent, $pushed, $headers )
use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init(); -
$transfers = 1; $cb = function( $parent, $pushed, $headers )
use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init(); -
$transfers = 1; $cb = function( $parent, $pushed, $headers )
use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init(); -
$mh = curl_multi_init(); curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX ); curl_multi_setopt($mh,
CURLMOPT_PUSHFUNCTION, $cb ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://localhost/" ); -
$mh = curl_multi_init(); curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX ); curl_multi_setopt($mh,
CURLMOPT_PUSHFUNCTION, $cb ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://localhost/" ); -
$mh = curl_multi_init(); curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX ); curl_multi_setopt($mh,
CURLMOPT_PUSHFUNCTION, $cb ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://localhost/" ); -
$mh = curl_multi_init(); curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX ); curl_multi_setopt($mh,
CURLMOPT_PUSHFUNCTION, $cb ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://localhost/" ); -
$mh = curl_multi_init(); curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX ); curl_multi_setopt($mh,
CURLMOPT_PUSHFUNCTION, $cb ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://localhost/" ); -
curl_setopt($ch, CURLOPT_URL, "https://localhost/" ); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_multi_add_handle($mh, $ch); $active = null; do { -
curl_setopt($ch, CURLOPT_URL, "https://localhost/" ); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_multi_add_handle($mh, $ch); $active = null; do { -
curl_setopt($ch, CURLOPT_URL, "https://localhost/" ); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_multi_add_handle($mh, $ch); $active = null; do { -
do { $status = curl_multi_exec($mh, $active); do { $info =
curl_multi_info_read($mh); if (false !== $info && $info['msg'] == CURLMSG_DONE) { $handle = $info['handle']; if ($handle !== null) { $transfers--; // remaining requests $out = curl_multi_getcontent( $info['handle'] ); // Response body -
do { $status = curl_multi_exec($mh, $active); do { $info =
curl_multi_info_read($mh); if (false !== $info && $info['msg'] == CURLMSG_DONE) { $handle = $info['handle']; if ($handle !== null) { $transfers--; // remaining requests $out = curl_multi_getcontent( $info['handle'] ); // Response body -
do { $status = curl_multi_exec($mh, $active); do { $info =
curl_multi_info_read($mh); if (false !== $info && $info['msg'] == CURLMSG_DONE) { $handle = $info['handle']; if ($handle !== null) { $transfers--; // remaining requests $out = curl_multi_getcontent( $info['handle'] ); // Response body -
do { $status = curl_multi_exec($mh, $active); do { $info =
curl_multi_info_read($mh); if (false !== $info && $info['msg'] == CURLMSG_DONE) { $handle = $info['handle']; if ($handle !== null) { $transfers--; // remaining requests $out = curl_multi_getcontent( $info['handle'] ); // Response body -
do { $status = curl_multi_exec($mh, $active); do { $info =
curl_multi_info_read($mh); if (false !== $info && $info['msg'] == CURLMSG_DONE) { $handle = $info['handle']; if ($handle !== null) { $transfers--; // remaining requests $out = curl_multi_getcontent( $info['handle'] ); // Response body -
do { $status = curl_multi_exec($mh, $active); do { $info =
curl_multi_info_read($mh); if (false !== $info && $info['msg'] == CURLMSG_DONE) { $handle = $info['handle']; if ($handle !== null) { $transfers--; // remaining requests $out = curl_multi_getcontent( $info['handle'] ); // Response body -
$handle = $info['handle']; if ($handle !== null) { $transfers--; //
remaining requests $out = curl_multi_getcontent( $info['handle'] ); // Response body curl_multi_remove_handle($mh, $handle); curl_close($handle); } } } while ($info); } while ($transfers); curl_multi_close($mh); -
$handle = $info['handle']; if ($handle !== null) { $transfers--; //
remaining requests $out = curl_multi_getcontent( $info['handle'] ); // Response body curl_multi_remove_handle($mh, $handle); curl_close($handle); } } } while ($info); } while ($transfers); curl_multi_close($mh); -
$handle = $info['handle']; if ($handle !== null) { $transfers--; //
remaining requests $out = curl_multi_getcontent( $info['handle'] ); // Response body curl_multi_remove_handle($mh, $handle); curl_close($handle); } } } while ($info); } while ($transfers); curl_multi_close($mh); -
$handle = $info['handle']; if ($handle !== null) { $transfers--; //
remaining requests $out = curl_multi_getcontent( $info['handle'] ); // Response body curl_multi_remove_handle($mh, $handle); curl_close($handle); } } } while ($info); } while ($transfers); curl_multi_close($mh); -
B LO G A P I + S E R
V E R P U S H -
class H2PushCache { static $cache = []; static $pushHandles =
[]; static function addPushHandle($headers, $handle) { foreach ($headers as $header) { if (strpos($header, ':path:') === 0) { $path = substr($header, 6); $url = curl_getinfo($handle)['url']; $url = str_replace( parse_url($url, PHP_URL_PATH), $path, $url ); self::$pushHandles[$url] = $handle; } } } static function add($handle) { -
class H2PushCache { static $cache = []; static $pushHandles =
[]; static function addPushHandle($headers, $handle) { foreach ($headers as $header) { if (strpos($header, ':path:') === 0) { $path = substr($header, 6); $url = curl_getinfo($handle)['url']; $url = str_replace( parse_url($url, PHP_URL_PATH), $path, -
class H2PushCache { static $cache = []; static $pushHandles =
[]; static function addPushHandle($headers, $handle) { foreach ($headers as $header) { if (strpos($header, ':path:') === 0) { $path = substr($header, 6); $url = curl_getinfo($handle)['url']; $url = str_replace( parse_url($url, PHP_URL_PATH), $path, -
class H2PushCache { static $cache = []; static $pushHandles =
[]; static function addPushHandle($headers, $handle) { foreach ($headers as $header) { if (strpos($header, ':path:') === 0) { $path = substr($header, 6); $url = curl_getinfo($handle)['url']; $url = str_replace( parse_url($url, PHP_URL_PATH), $path, -
class H2PushCache { static $cache = []; static $pushHandles =
[]; static function addPushHandle($headers, $handle) { foreach ($headers as $header) { if (strpos($header, ':path:') === 0) { $path = substr($header, 6); $url = curl_getinfo($handle)['url']; $url = str_replace( parse_url($url, PHP_URL_PATH), $path, -
static function addPushHandle($headers, $handle) { foreach ($headers as $header) {
if (strpos($header, ':path:') === 0) { $path = substr($header, 6); $url = curl_getinfo($handle)['url']; $url = str_replace( parse_url($url, PHP_URL_PATH), $path, $url ); self::$pushHandles[$url] = $handle; } } -
static function addPushHandle($headers, $handle) { foreach ($headers as $header) {
if (strpos($header, ':path:') === 0) { $path = substr($header, 6); $url = curl_getinfo($handle)['url']; $url = str_replace( parse_url($url, PHP_URL_PATH), $path, $url ); self::$pushHandles[$url] = $handle; } } -
static function add($handle) { $found = false; foreach (self::$pushHandles as
$url => $h) { if ($handle == $h) { $found = $url; } } if (!$found) { $found = curl_getinfo($handle)['url']; } -
static function add($handle) { $found = false; foreach (self::$pushHandles as
$url => $h) { if ($handle == $h) { $found = $url; } } if (!$found) { $found = curl_getinfo($handle)['url']; } -
static function add($handle) { $found = false; foreach (self::$pushHandles as
$url => $h) { if ($handle == $h) { $found = $url; } } if (!$found) { $found = curl_getinfo($handle)['url']; } -
self::$cache[$found] = curl_multi_getcontent($handle); } static function exists($url) { if
(isset(self::$cache[$url])) { return true; } return false; } -
self::$cache[$found] = curl_multi_getcontent($handle); } static function exists($url) { if
(isset(self::$cache[$url])) { return true; } return false; } -
{ if (isset(self::$cache[$url])) { return true; } return false; }
static function get($url) { return self::$cache[$url]; } } -
function get_request($url) { if (H2PushCache::exists($url)) { return H2PushCache::get($url); } $transfers
= 1; $cb = function ($parent, $pushed, $headers) use (&$transfers) { $transfers++; // increment to keep track of the number of concurrent requests H2PushCache::addPushHandle($headers, $pushed); return CURL_PUSH_OK; }; $mh = curl_multi_init(); curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX ); curl_multi_setopt($mh, CURLMOPT_PUSHFUNCTION, $cb ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url ); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2 ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 -
function get_request($url) { if (H2PushCache::exists($url)) { return H2PushCache::get($url); } $transfers
= 1; $cb = function ($parent, $pushed, $headers) use (&$transfers) { $transfers++; // increment to keep track of the number of concurrent requests H2PushCache::addPushHandle($headers, -
function get_request($url) { if (H2PushCache::exists($url)) { return H2PushCache::get($url); } $transfers
= 1; $cb = function ($parent, $pushed, $headers) use (&$transfers) { $transfers++; // increment to keep track of the number of concurrent requests H2PushCache::addPushHandle($headers, -
function get_request($url) { if (H2PushCache::exists($url)) { return H2PushCache::get($url); } $transfers
= 1; $cb = function ($parent, $pushed, $headers) use (&$transfers) { $transfers++; // increment to keep track of the number of concurrent requests H2PushCache::addPushHandle($headers, -
function get_request($url) { if (H2PushCache::exists($url)) { return H2PushCache::get($url); } $transfers
= 1; $cb = function ($parent, $pushed, $headers) use (&$transfers) { $transfers++; // increment to keep track of the number of concurrent requests H2PushCache::addPushHandle($headers, -
$transfers = 1; $cb = function ($parent, $pushed, $headers) use
(&$transfers) { $transfers++; H2PushCache::addPushHandle($headers, $pushed); return CURL_PUSH_OK; }; $mh = curl_multi_init(); curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX -
$transfers = 1; $cb = function ($parent, $pushed, $headers) use
(&$transfers) { $transfers++; H2PushCache::addPushHandle($headers, $pushed); return CURL_PUSH_OK; }; $mh = curl_multi_init(); curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX -
do { $status = curl_multi_exec($mh, $active); do { $info =
curl_multi_info_read($mh); if (false !== $info && $info['msg'] == CURLMSG_DONE) { $handle = $info['handle']; if ($handle !== null) { $transfers--; // decrement remaining H2PushCache::add($handle); curl_multi_remove_handle($mh, -
do { $status = curl_multi_exec($mh, $active); do { $info =
curl_multi_info_read($mh); if (false !== $info && $info['msg'] == CURLMSG_DONE) { $handle = $info['handle']; if ($handle !== null) { $transfers--; // decrement remaining H2PushCache::add($handle); curl_multi_remove_handle($mh, -
$transfers--; // decrement remaining H2PushCache::add($handle); curl_multi_remove_handle($mh, $handle); curl_close($handle); } }
} while ($info); } while ($transfers); curl_multi_close($mh); return H2PushCache::get($url); } -
$transfers--; // decrement remaining H2PushCache::add($handle); curl_multi_remove_handle($mh, $handle); curl_close($handle); } }
} while ($info); } while ($transfers); curl_multi_close($mh); return H2PushCache::get($url); } -
$url = 'https://example/post/1'; $response = get_request($url); $post = json_decode($response); $response
= get_request($post->comments); $comments = json_decode($reponse); $response = get_request($post->author); $author = json_decode($response); -
$url = 'https://example/post/1'; $response = get_request($url); $post = json_decode($response); $response
= get_request($post->comments); $comments = json_decode($reponse); $response = get_request($post->author); $author = json_decode($response); -
$url = 'https://example/post/1'; $response = get_request($url); $post = json_decode($response); $response
= get_request($post->comments); $comments = json_decode($reponse); $response = get_request($post->author); $author = json_decode($response); -
$url = 'https://example/post/1'; $response = get_request($url); $post = json_decode($response); $response
= get_request($post->comments); $comments = json_decode($reponse); $response = get_request($post->author); $author = json_decode($response); -
$url = 'https://example/post/1'; $response = get_request($url); $post = json_decode($response); $response
= get_request($post->comments); $comments = json_decode($reponse); $response = get_request($post->author); $author = json_decode($response); -
$url = 'https://example/post/1'; $response = get_request($url); $post = json_decode($response); $response
= get_request($post->comments); $comments = json_decode($reponse); $response = get_request($post->author); $author = json_decode($response);