Created
August 14, 2013 11:39
-
-
Save ronnyandre/6230278 to your computer and use it in GitHub Desktop.
Simultaneously download websites using PHP and 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 | |
use Guzzle\Http\Client, | |
Guzzle\Common\Exception\MultiTransferException; | |
$client = new Client('http://graph.facebook.com'); | |
try { | |
$responses = $client->send(array( | |
$client->get('/' . urlencode('http://tech.vg.no')), | |
$client->get('/' . urlencode('http://www.vg.no')), | |
)); | |
foreach ($responses as $response) { | |
echo $response->getBody(); | |
} | |
} catch (MultiTransferException $e) { | |
echo 'The following exceptions were encountered:' . PHP_EOL; | |
foreach ($e as $exception) { | |
echo $exception->getMessage() . PHP_EOL; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment