Slide 1

Slide 1 text

Guzzle PHP! Makes HTTP Easy! by @jeremeamia • for @NomadPHP!

Slide 2

Slide 2 text

Hi, I’m Jeremy.! @jeremeamia! Seattle PHP User Group! @seaphp! AWS SDK for PHP! @awsforphp!

Slide 3

Slide 3 text

AWS SDK for PHP ! ! Built on Guzzle!!

Slide 4

Slide 4 text

Guzzle! ! Thanks to! @mtdowling! for Guzzle!! #GuzzlePHP! !

Slide 5

Slide 5 text

HTTP is Kinda Hard! •  URLs! •  Hosts! •  Headers! •  Query strings! •  GET/POST/PUT/etc.! •  Status codes! •  cURL! •  Proxies! •  Message Integrity! •  HTTPS! •  Post bodies! •  Ports! •  REST! •  Cookies! •  Hypermedia! •  Streams! •  RFCs! •  Caching!

Slide 6

Slide 6 text

Guzzle! is…!

Slide 7

Slide 7 text

…an open source PHP library!

Slide 8

Slide 8 text

…a well-crafted PHP library! •  Follows good OOP patterns and practices! •  Follows PSRs 1–4! •  Uses good tools: Composer, Travis CI, PHPUnit, GitHub, make, sphinx! •  High test coverage! •  Good documentation! •  Extensible via DI, callbacks, and events!

Slide 9

Slide 9 text

…an HTTP client! e.g., https://api.github.com!

Slide 10

Slide 10 text

…an HTTP client! $client  =  new  GuzzleHttp\Client([          'base_url'  =>  'https://api.github.com'   ]);   $response  =  $client-­‐>get('user',  [          'headers'  =>  [                  'Accept'  =>  'application/json'          ]   ]);   echo  $response-­‐>getStatusCode();   print_r($response-­‐>json());  

Slide 11

Slide 11 text

…an HTTP client! $r  =  $client-­‐>METHOD('PATH',  [PARAMS]);    

Slide 12

Slide 12 text

…an HTTP client! $r  =  $client-­‐>METHOD('PATH',  [PARAMS]);   $r  =  $client-­‐>get('PATH',  [PARAMS]);   $r  =  $client-­‐>post('PATH',  [PARAMS]);   $r  =  $client-­‐>put('PATH',  [PARAMS]);   $r  =  $client-­‐>delete('PATH',  [PARAMS]);   $r  =  $client-­‐>head('PATH',  [PARAMS]);   $r  =  $client-­‐>options('PATH',  [PARAM]);    

Slide 13

Slide 13 text

…an HTTP client! $r  =  $client-­‐>METHOD('PATH',  [          'headers'  =>  […],          'body'        =>  […],          'query'      =>  […],          'cookies'  =>  […],          'timeout'  =>  […],          'proxy'      =>  […],      //  …   ]);    

Slide 14

Slide 14 text

…an HTTP client! $r  =  $client-­‐>METHOD('PATH',  [PARAMS]);    

Slide 15

Slide 15 text

…packed with features! •  Pluggable HTTP adapters! •  Can send requests serially or in parallel! •  Doesn't require cURL, but uses it by default! •  Streams data for both uploads & downloads! •  Provides event hooks & plugins for cookies, caching, logging, OAuth, mocks, etc.! •  Keep-Alive & connection pooling! •  SSL Verification & Connection timeouts!

Slide 16

Slide 16 text

…a web service client framework! $s3  =  Aws\S3\S3Client::factory();   $result  =  $s3-­‐>listObjects([          'Bucket'  =>  $bucket   ]);   foreach  ($result['Contents']  as  $obj)  {          echo  $obj['Key'];   );  

Slide 17

Slide 17 text

…popular! •  Over 3900 stars on GitHub! •  Used in many projects including! – Drupal 8! – Goutte! – AWS SDK for PHP! – Laravel Mail Component! – Tumblr Client! – Nearly 1000 other Packagist packages!

Slide 18

Slide 18 text

And now! a story about Guzzle by! @phpbard!

Slide 19

Slide 19 text

This is a story about an elePHPant named Guzzle.! She consumes lots of data. But how? It's no puzzle.!

Slide 20

Slide 20 text

Armed with HTTP, she knows how to transport! Text and files of any size and sort.!

Slide 21

Slide 21 text

From client to server, and from server to client,! Her requests and responses are RFC compliant.!

Slide 22

Slide 22 text

And beyond the basics of just cookie and header.! There's much more to Guzzle that just makes her better:!

Slide 23

Slide 23 text

From parallel requests, from events and plugins,! To web service descriptions. And this just begins…!

Slide 24

Slide 24 text

To show you all that Guzzle can do! To help you consume your web services too.!

Slide 25

Slide 25 text

! ! ♫ If more PHP poetry you think you can swallow,! ♫ On Twitter and Tumblr, @phpbard you should follow.!

Slide 26

Slide 26 text

4! Guzzle! What's New?!

Slide 27

Slide 27 text

What's New in Guzzle 4?! •  Improved performance! •  Simpler interfaces! •  Smaller core library! •  Easier event system! •  Requires PHP 5.4! •  No longer requires cURL! •  Custom service descriptions!

Slide 28

Slide 28 text

Parallel Requests are Better!   $client-­‐>sendAll($requests,  [          'complete'  =>  function(CompleteEvent  $e)  {                  //  Do  something          },          'error'  =>  function(ErrorEvent  $e)  {                  //  Do  something          }   ]);  

Slide 29

Slide 29 text

Parallel Requests are Better! V3! V4!

Slide 30

Slide 30 text

Parallel Requests are Better! Rolling Queues   V3! V4!

Slide 31

Slide 31 text

Guzzle Resources – V3 vs. V4! V3   V4   Namespace   Guzzle! GuzzleHttp! GitHub   guzzle/guzzle3! guzzle/guzzle! Package   guzzle/guzzle! guzzlehttp/guzzle! Docs   guzzle3.readthedocs.org! guzzlephp.org! This  allows  you  to  use  Guzzle  3  and  4  in  the  same  project.   (And  this  has  actually  happened,  too)  

Slide 32

Slide 32 text

Guzzle 4 Packages! •  guzzlehttp/guzzle! •  guzzlehttp/streams! •  guzzlehttp/command! •  guzzlehttp/guzzle-services! •  guzzlehttp/retry-subscriber! •  guzzlehttp/log-subscriber! •  guzzlehttp/message-integrity-subscriber! •  guzzlehttp/oauth-subscriber! •  guzzlehttp/progress-subscriber!

Slide 33

Slide 33 text

Guzzle 4 Packages! •  guzzlehttp/guzzle! •  guzzlehttp/streams! •  guzzlehttp/command! •  guzzlehttp/guzzle-services! •  guzzlehttp/retry-subscriber! •  guzzlehttp/log-subscriber! •  guzzlehttp/message-integrity-subscriber! •  guzzlehttp/oauth-subscriber! •  guzzlehttp/progress-subscriber! Guzzle HTTP Layer!

Slide 34

Slide 34 text

Guzzle 4 Packages! •  guzzlehttp/guzzle! •  guzzlehttp/streams! •  guzzlehttp/command! •  guzzlehttp/guzzle-services! •  guzzlehttp/retry-subscriber! •  guzzlehttp/log-subscriber! •  guzzlehttp/message-integrity-subscriber! •  guzzlehttp/oauth-subscriber! •  guzzlehttp/progress-subscriber! Guzzle Service Layer!

Slide 35

Slide 35 text

Guzzle 4 Packages! •  guzzlehttp/guzzle! •  guzzlehttp/streams! •  guzzlehttp/command! •  guzzlehttp/guzzle-services! •  guzzlehttp/retry-subscriber! •  guzzlehttp/log-subscriber! •  guzzlehttp/message-integrity-subscriber! •  guzzlehttp/oauth-subscriber! •  guzzlehttp/progress-subscriber! Guzzle Plugins!

Slide 36

Slide 36 text

5! Guzzle! What's New?!

Slide 37

Slide 37 text

What's New in Guzzle 5?! •  Non-blocking "Future" responses! – Makes true async requests possible! – Compatible with things like ReactPHP! •  New guts based on guzzle/guzzle-ring! •  Retry subscriber no longer blocking! •  New "progress" event for tracking! upload/download progress.!

Slide 38

Slide 38 text

Looking for a Guzzle Example?! Basic Twilio client implementation! http://ow.ly/x7ugf!

Slide 39

Slide 39 text

Guzzle PHP! Makes HTTP Easy! by @jeremeamia • for @NomadPHP!