completeRequest() or loop(), followed by extractNewResponses().
- completeRequest() gives you all responses of the specified request (while simultaneously receiving responses to other requests). e.g.
$setRequest = new Request('/ip/firewall/address-list/remove');
$setRequest->setArgument('numbers', $id);
$setRequest->setTag('11');
$client->sendAsync($setRequest);
//Other sendAsync() calls here
$responses = $client->completeRequest('11');
//$responses contains every response of the "11" request
- extractNewResponses() gives you everything received within a time limit specified at loop() (or, if completeRequest() was called for another request - everything that was received for that other request back then). e.g.
$setRequest = new Request('/ip/firewall/address-list/remove');
$setRequest->setArgument('numbers', $id);
$setRequest->setTag('11');
$client->sendAsync($setRequest);
//Other sendAsync() calls here
$client->loop(4);
$responses1 = $client->extractNewResponses('11');
//$responses1 contains every response of the "11" request that the router gave in the past 4 seconds
$client->loop(3);
$responses2 = $client->extractNewResponses('11');
//$responses1 contains every response of the "11" request received in the last 3 seconds, not including those that the last extractNewResponses() call returned.
If all you need is to have a request, and process its responses
immediately, it's easier if you just use sendSync() instead of sendAsync(). e.g.
$setRequest = new Request('/ip/firewall/address-list/remove');
$setRequest->setArgument('numbers', $id);
$setRequest->setTag('11');
$responses = $client->sendSync($setRequest);
//$responses contains every response of the "11" request
BTW, you can also use a callback for each response (which would be my personal preference on most occasions) instead of processing the full collection, e.g.
$setRequest = new Request('/ip/firewall/address-list/remove');
$setRequest->setArgument('numbers', $id);
$setRequest->setTag('11');
$client->sendAsync($setRequest, function($response) {
//Process each response here
});
$client->completeRequest('11');//Start receiving all responses for "11", with each one of them executing the callback above.