Skip to content

Instantly share code, notes, and snippets.

@reshadman
Created June 26, 2014 12:25
Show Gist options
  • Save reshadman/5b109bc3c26ce372276b to your computer and use it in GitHub Desktop.
Save reshadman/5b109bc3c26ce372276b to your computer and use it in GitHub Desktop.
25 Async request with Guzzle
<?php
public function __construct (\GuzzleHttp\Client $client)
{
$this->client = $client;
}
public function asyncReqs ()
{
$requests = [];
for ( $i = 1; $i <= 25 ; $i++)
{
$requests [] = $this->client->createRequest('GET', 'http://httpbin.org');
}
\Log::info("I am total start time: " . time() . " \n\n");
$this->client->sendAll($requests,[
'before' => function (BeforeEvent $event){
\Log::info("I am " . $event->getRequest()->getMethod() . ' start time: ' . time());
},
'complete' => function (CompleteEvent $event){
\Log::info("I am " . $event->getRequest()->getMethod() . ' finish time: ' . time());
}
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment