history-plugin.rst 720 B

123456789101112131415161718192021222324
  1. ==============
  2. History plugin
  3. ==============
  4. The history plugin tracks all of the requests and responses sent through a request or client. This plugin can be
  5. useful for crawling or unit testing. By default, the history plugin stores up to 10 requests and responses.
  6. .. code-block:: php
  7. use Guzzle\Http\Client;
  8. use Guzzle\Plugin\History\HistoryPlugin;
  9. $client = new Client('http://www.test.com/');
  10. // Add the history plugin to the client object
  11. $history = new HistoryPlugin();
  12. $history->setLimit(5);
  13. $client->addSubscriber($history);
  14. $client->get('http://www.yahoo.com/')->send();
  15. echo $history->getLastRequest();
  16. echo $history->getLastResponse();
  17. echo count($history);