Skip to content

Instantly share code, notes, and snippets.

@huglester
Forked from raul782/guzzle-404.php
Created March 4, 2013 13:56
Show Gist options
  • Save huglester/5082390 to your computer and use it in GitHub Desktop.
Save huglester/5082390 to your computer and use it in GitHub Desktop.
<?php require_once(__DIR__.'/../../vendor/autoload.php');
use Guzzle\Http\Client;
use Guzzle\Common\Event;
use Guzzle\Http\Message\Request;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\BadResponseException;
$url = 'http://www.amazon.com';
$client = new Client($url);
$client->getEventDispatcher()->addListener('request.error', function(Event $event) {
if ($event['response']->getStatusCode() == 404) {
$newResponse = new Response($event['response']->getStatusCode());
$event['response'] = $newResponse;
$event->stopPropagation();
}
});
$uri = 'XX';
$request = $client->get('/'.$uri);
$response = $request->send();
echo $uri.'::'.$response->getStatusCode();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment