b5a6d756cee268fdc37a7ac82d910b90ec29abfb
[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\InvalidArgumentException
22 * http\Exception\BadMethodCallException
23 * http\Exception\RuntimeException
24
25 ## Example:
26
27 (new http\Client)->enqueue(new http\Client\Request("GET", "http://php.net"),
28 function(http\Client\Response $res) {
29 printf("%s returned %d\n", $res->getTransferInfo("effective_url"), $res->getResponseCode());
30 return true; // dequeue
31 })->send();
32
33 Yields:
34
35 http://php.net/ returned 200