Created
June 26, 2014 12:25
-
-
Save reshadman/5b109bc3c26ce372276b to your computer and use it in GitHub Desktop.
25 Async request with Guzzle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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