flush
[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 See http\Client::dequeue() and http\Client::send().
7
8 ## Params:
9
10 * http\Client\Request $request
11 The request to enqueue.
12 * Optional callable $cb
13 A callback to automatically call when the request has finished.
14
15 ## Returns:
16
17 * http\Client, self.
18
19 ## Throws:
20
21 * http\Exception.
22
23 ## Example:
24
25 (new http\Client)->enqueue(new http\Client\Request("GET", "http://php.net"),
26 function(http\Client\Response $res) {
27 printf("%s returned %d\n", $res->getTransferInfo("effective_url"), $res->getResponseCode());
28 return true; // dequeue
29 })->send();
30
31 Yields:
32
33 http://php.net/ returned 200