Update enqueue.md
[mdref/mdref-http] / http / Client / enqueue.md
1 # http\Client http\Client::enqueue(http\Client\Request $request[, callable $cb])
2
3 Add another http\Client\Request to the request queue.
4 If the optional callback $cb returns true, the request will be automatically dequeued.
5
6 > ***Note:***
7 > The http\Client\Response object resulting from the request is always stored in an internal storage, __even__ when callback is used, because of that, the memory may grow up significantly if you send many many requests using the same http\Client instance... In that case, to keep memory as low as possible, it is advised to call http\Client::getResponse() in the callback or to call http\Client::reset() after each http\Client::send() to free some ressources.
8
9 See http\Client::dequeue() and http\Client::send().
10
11
12 ## Params:
13
14 * http\Client\Request $request
15 The request to enqueue.
16 * Optional callable $cb
17 A callback to automatically call when the request has finished.
18
19 ## Returns:
20
21 * http\Client, self.
22
23 ## Throws:
24
25 * http\Exception\InvalidArgumentException
26 * http\Exception\BadMethodCallException
27 * http\Exception\RuntimeException
28
29 ## Example:
30
31 (new http\Client)->enqueue(new http\Client\Request("GET", "http://php.net"),
32 function(http\Client\Response $res) {
33 printf("%s returned %d\n", $res->getTransferInfo("effective_url"), $res->getResponseCode());
34 return true; // dequeue
35 })->send();
36
37 Yields:
38
39 http://php.net/ returned 200