Slide 1

Slide 1 text

H T T P/ 2 A N D A SY N C H R O N O U S A P I S

Slide 2

Slide 2 text

F E TC H I N G A B LO G P O ST + CO M M E N TS CC-BY: John Trainor

Slide 3

Slide 3 text

Ȑ

Slide 4

Slide 4 text

Ȑ

Slide 5

Slide 5 text

Ȑ GET /post/1

Slide 6

Slide 6 text

Ȑ GET /post/1 200 OK application/json

Slide 7

Slide 7 text

{ "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" }

Slide 8

Slide 8 text

{ "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" }

Slide 9

Slide 9 text

Ȑ

Slide 10

Slide 10 text

Ȑ

Slide 11

Slide 11 text

Ȑ GET /posts/1/comments

Slide 12

Slide 12 text

Ȑ GET /posts/1/comments 200 OK application/json

Slide 13

Slide 13 text

[ "http://example.org/post/1/comment/1", "http://example.org/post/1/comment/2", "http://example.org/post/1/comment/3", "http://example.org/post/1/comment/4" ]

Slide 14

Slide 14 text

Ȑ

Slide 15

Slide 15 text

Ȑ

Slide 16

Slide 16 text

Ȑ GET /post/example/comments/1

Slide 17

Slide 17 text

Ȑ GET /post/example/comments/ 200 OK application/json 1

Slide 18

Slide 18 text

2 Ȑ GET /post/example/comments/ 200 OK application/json 1

Slide 19

Slide 19 text

2 3 Ȑ GET /post/example/comments/ 200 OK application/json 1

Slide 20

Slide 20 text

2 3 4 Ȑ GET /post/example/comments/ 200 OK application/json 1

Slide 21

Slide 21 text

{ "type": "comment", "id": "1", "title": "FIRST!", "author": "http://example.com/post/1/comment/1/author" }

Slide 22

Slide 22 text

6 requests (possibly connections)

Slide 23

Slide 23 text

14 requests (possibly connections)

Slide 24

Slide 24 text

L E T ’ S M U LT I P L E X !

Slide 25

Slide 25 text

M U LT I P L E X E D Ȑ

Slide 26

Slide 26 text

M U LT I P L E X E D Ȑ GET /post/example/comments/3

Slide 27

Slide 27 text

M U LT I P L E X E D Ȑ GET /post/example/comments/3 GET /post/example/comments/1

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

D E P E N D E N C I E S

Slide 34

Slide 34 text

{ "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" } } ] }

Slide 35

Slide 35 text

{ "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",

Slide 36

Slide 36 text

{ "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",

Slide 37

Slide 37 text

"gravatar": "fee39f0c0ffb29d9ac21607ed188be6b" }, "comments": [ { "type": "comment", "id": "1", "content": "FIRST!", "author": { "type": "author", "id": 2, "name": "Jill Random", "gravatar": "706b16b2fb732ab6079a10fea61d078b" } }, { "type": "comment", "id": "2",

Slide 38

Slide 38 text

} }, { "type": "comment", "id": "3", "content": "third", "author": { "type": "author", "id": 1, "name": "Davey Shafik", "twitter": "@dshafik", "gravatar": "fee39f0c0ffb29d9ac21607ed188be6b" } }, { "type": "comment", "id": "4",

Slide 39

Slide 39 text

} }, { "type": "comment", "id": "3", "content": "third", "author": { "type": "author", "id": 1, "name": "Davey Shafik", "twitter": "@dshafik", "gravatar": "fee39f0c0ffb29d9ac21607ed188be6b" } }, { "type": "comment", "id": "4",

Slide 40

Slide 40 text

} }, { "type": "comment", "id": "4", "content": "fourth", "author": { "type": "author", "id": 2, "name": "Jill Random", "gravatar": "706b16b2fb732ab6079a10fea61d078b" } } ] }

Slide 41

Slide 41 text

S E R V E R P US H CC-BY: Steven Depolo

Slide 42

Slide 42 text

Ȑ

Slide 43

Slide 43 text

Ȑ

Slide 44

Slide 44 text

Ȑ GET /post/1

Slide 45

Slide 45 text

Ȑ GET /post/1 200 OK application/json

Slide 46

Slide 46 text

GET /post/1/comments Ȑ GET /post/1 200 OK application/json

Slide 47

Slide 47 text

GET /post/1/comments GET /post/1/comment/1 Ȑ GET /post/1 200 OK application/json

Slide 48

Slide 48 text

Ȑ GET /post/1/comments GET /post/1/comment/1

Slide 49

Slide 49 text

Ȑ GET /post/1/comment/2 GET /post/1/comment/3 GET /post/1/comment/4 GET /post/1/comments GET /post/1/comment/1

Slide 50

Slide 50 text

Ȑ 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

Slide 51

Slide 51 text

Ȑ 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

Slide 52

Slide 52 text

D E P E N D E N C I E S CC-BY-SA 2.0: David Gamez

Slide 53

Slide 53 text

A P I R E Q U E ST Ɇ ɂ Ȑ

Slide 54

Slide 54 text

A P I R E Q U E ST Ɇ ɂ Ȑ

Slide 55

Slide 55 text

A P I R E Q U E ST GET /post/1 Ɇ ɂ Ȑ

Slide 56

Slide 56 text

A P I R E Q U E ST GET /post/1 200 OK application/json Ɇ ɂ Ȑ

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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/…

Slide 60

Slide 60 text

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/…

Slide 61

Slide 61 text

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/…

Slide 62

Slide 62 text

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/…

Slide 63

Slide 63 text

CO D E

Slide 64

Slide 64 text

$numRequests = 378;

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

$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

Slide 67

Slide 67 text

$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

Slide 68

Slide 68 text

$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

Slide 69

Slide 69 text

$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

Slide 70

Slide 70 text

$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

Slide 71

Slide 71 text

$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

Slide 72

Slide 72 text

4 7 . 6 7 
 s e co n d s CC-BY: Hernán Piñera

Slide 73

Slide 73 text

$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

Slide 74

Slide 74 text

$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

Slide 75

Slide 75 text

$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

Slide 76

Slide 76 text

$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

Slide 77

Slide 77 text

$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

Slide 78

Slide 78 text

$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

Slide 79

Slide 79 text

6 2 . 1 9 
 s e co n d s CC-BY-NC: Scott Beckner

Slide 80

Slide 80 text

$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

Slide 81

Slide 81 text

$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

Slide 82

Slide 82 text

$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

Slide 83

Slide 83 text

$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

Slide 84

Slide 84 text

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); } }

Slide 85

Slide 85 text

8 . 6 6 
 s e co n d s

Slide 86

Slide 86 text

$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();

Slide 87

Slide 87 text

$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;

Slide 88

Slide 88 text

$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
 );

Slide 89

Slide 89 text

$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
 );

Slide 90

Slide 90 text

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); } }

Slide 91

Slide 91 text

2 . 1 4 
 s e co n d s CC-BY: motoracereports

Slide 92

Slide 92 text

H A N D L I N G S E R V E R P US H

Slide 93

Slide 93 text

$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);

Slide 94

Slide 94 text

$transfers = 1; $cb = function( $parent, $pushed, $headers ) use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init();

Slide 95

Slide 95 text

$transfers = 1; $cb = function( $parent, $pushed, $headers ) use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init();

Slide 96

Slide 96 text

$transfers = 1; $cb = function( $parent, $pushed, $headers ) use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init();

Slide 97

Slide 97 text

$transfers = 1; $cb = function( $parent, $pushed, $headers ) use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init();

Slide 98

Slide 98 text

$transfers = 1; $cb = function( $parent, $pushed, $headers ) use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init();

Slide 99

Slide 99 text

$transfers = 1; $cb = function( $parent, $pushed, $headers ) use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init();

Slide 100

Slide 100 text

$transfers = 1; $cb = function( $parent, $pushed, $headers ) use (&$transfers) { $transfers++; // increment to keep track of return CURL_PUSH_OK; }; $mh = curl_multi_init();

Slide 101

Slide 101 text

$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/"
 );

Slide 102

Slide 102 text

$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/"
 );

Slide 103

Slide 103 text

$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/"
 );

Slide 104

Slide 104 text

$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/"
 );

Slide 105

Slide 105 text

$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/"
 );

Slide 106

Slide 106 text

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 {

Slide 107

Slide 107 text

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 {

Slide 108

Slide 108 text

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 {

Slide 109

Slide 109 text

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

Slide 110

Slide 110 text

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

Slide 111

Slide 111 text

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

Slide 112

Slide 112 text

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

Slide 113

Slide 113 text

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

Slide 114

Slide 114 text

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

Slide 115

Slide 115 text

$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);

Slide 116

Slide 116 text

$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);

Slide 117

Slide 117 text

$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);

Slide 118

Slide 118 text

$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);

Slide 119

Slide 119 text

B LO G A P I + S E R V E R P U S H

Slide 120

Slide 120 text

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) {

Slide 121

Slide 121 text

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,

Slide 122

Slide 122 text

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,

Slide 123

Slide 123 text

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,

Slide 124

Slide 124 text

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,

Slide 125

Slide 125 text

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; } }

Slide 126

Slide 126 text

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; } }

Slide 127

Slide 127 text

static function add($handle) { $found = false; foreach (self::$pushHandles as $url => $h) { if ($handle == $h) { $found = $url; } } if (!$found) { $found = curl_getinfo($handle)['url']; }

Slide 128

Slide 128 text

static function add($handle) { $found = false; foreach (self::$pushHandles as $url => $h) { if ($handle == $h) { $found = $url; } } if (!$found) { $found = curl_getinfo($handle)['url']; }

Slide 129

Slide 129 text

static function add($handle) { $found = false; foreach (self::$pushHandles as $url => $h) { if ($handle == $h) { $found = $url; } } if (!$found) { $found = curl_getinfo($handle)['url']; }

Slide 130

Slide 130 text

self::$cache[$found] = 
 curl_multi_getcontent($handle); } static function exists($url) { if (isset(self::$cache[$url])) { return true; } return false; }

Slide 131

Slide 131 text

self::$cache[$found] = 
 curl_multi_getcontent($handle); } static function exists($url) { if (isset(self::$cache[$url])) { return true; } return false; }

Slide 132

Slide 132 text

{ if (isset(self::$cache[$url])) { return true; } return false; } static function get($url) { return self::$cache[$url]; } }

Slide 133

Slide 133 text

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

Slide 134

Slide 134 text

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,

Slide 135

Slide 135 text

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,

Slide 136

Slide 136 text

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,

Slide 137

Slide 137 text

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,

Slide 138

Slide 138 text

$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

Slide 139

Slide 139 text

$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

Slide 140

Slide 140 text

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,

Slide 141

Slide 141 text

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,

Slide 142

Slide 142 text

$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); }

Slide 143

Slide 143 text

$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); }

Slide 144

Slide 144 text

$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);

Slide 145

Slide 145 text

$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);

Slide 146

Slide 146 text

$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);

Slide 147

Slide 147 text

$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);

Slide 148

Slide 148 text

$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);

Slide 149

Slide 149 text

$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);

Slide 150

Slide 150 text

T H A N K S !