update for 4.1.0
[mdref/mdref-http] / http / Client / getHistory.md
1 # http\Message http\Client::getHistory()
2
3 Simply returns the http\Message chain representing the request/response history.
4
5 > ***NOTE:***
6 > The history is only recorded while http\Client::$recordHistory is true.
7
8 ## Params:
9
10 None.
11
12 ## Returns:
13
14 * http\Message, the request/response message chain representing the client's history.
15
16 ## Throws:
17
18 * http\Exception\InvalidArgumentException
19
20 ## Example:
21
22 <?php
23 $client = new http\Client;
24 $client->enqueue(new http\Client\Request("HEAD", "http://php.net"));
25 $client->enqueue(new http\Client\Request("HEAD", "http://pecl.php.net"));
26 $client->enqueue(new http\Client\Request("HEAD", "http://pear.php.net"));
27 $client->recordHistory = true;
28 $client->send();
29
30 echo $client->getHistory()->toString(true);
31
32 Yields:
33
34 HEAD / HTTP/1.1
35 User-Agent: PECL::HTTP/2.0.0dev (PHP/5.5.5)
36 Host: pear.php.net
37 Accept: */*
38 Content-Length: 0
39
40 HTTP/1.1 200 OK
41 Date: Mon, 04 Nov 2013 15:41:48 GMT
42 Server: ...
43 X-Powered-By: PHP/5.3.6
44 Connection: close
45 Content-Type: text/html; charset=UTF-8
46 Content-Length: 0
47
48 HEAD / HTTP/1.1
49 User-Agent: PECL::HTTP/2.0.0dev (PHP/5.5.5)
50 Host: pecl.php.net
51 Accept: */*
52 Content-Length: 0
53
54 HTTP/1.1 200 OK
55 Date: Mon, 04 Nov 2013 14:34:02 GMT
56 Server: ...
57 X-Powered-By: PHP/5.2.17
58 Set-Cookie: ...
59 Expires: Thu, 19 Nov 1981 08:52:00 GMT
60 Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
61 Pragma: no-cache
62 Connection: close
63 Content-Type: text/html; charset=ISO-8859-1
64 Content-Length: 0
65
66 HEAD / HTTP/1.1
67 User-Agent: PECL::HTTP/2.0.0dev (PHP/5.5.5)
68 Host: php.net
69 Accept: */*
70 Content-Length: 0
71
72 HTTP/1.1 200 OK
73 Server: ...
74 Date: Mon, 04 Nov 2013 14:34:08 GMT
75 Content-Type: text/html;charset=utf-8
76 Connection: keep-alive
77 X-Powered-By: PHP/5.5.4-1
78 Content-Language: en
79 Set-Cookie: ...
80 Last-Modified: Mon, 04 Nov 2013 21:00:36 GMT
81 Content-Length: 0