flush
[mdref/mdref-http] / http / Client / once.md
1 # bool http\Client::once()
2
3 Perform outstanding transfer actions.
4 See http\Client::wait() for the completing interface.
5
6 ## Params:
7
8 None.
9
10 ## Returns:
11
12 * bool, true if there are more transfers to complete.
13
14 ## Example:
15
16 <?php
17 $client = new http\Client;
18 $client->enqueue(new http\Client\Request("HEAD", "http://php.net"));
19 $client->enqueue(new http\Client\Request("HEAD", "http://pecl.php.net"));
20 $client->enqueue(new http\Client\Request("HEAD", "http://pear.php.net"));
21
22 printf("Transfers ongoing");
23 while ($client->once()) {
24 // do something else here while the network transfers are busy
25 printf(".");
26 // and then call http\Client::wait() to wait for new input
27 $client->wait();
28 }
29 printf("\n");
30
31 while ($res = $client->getResponse()) {
32 printf("%s returned %d\n", $res->getTransferInfo("effective_url"),
33 $res->getResponseCode());
34 }
35
36 Yields:
37
38 Transfers ongoing....................................................
39 http://php.net/ returned 200
40 http://pecl.php.net/ returned 200
41 http://pear.php.net/ returned 200