1.I tried to use the second code. It didn’t work again please advise;
That’s odd… I tried it myself, just replacing the IP and credentials (I don’t have a second router, so I just made the router do a bandwidth test with one of its other IPs), and it worked. It does however take surprisingly long for it to finish. It’s almost as if RouterOS doesn’t honor the duration argument, or is perhaps multiplying it by a large factor. The interval argument seems to work though, so if you want your data to span 10 seconds, you’d need to add interval=1 as an argument, while keeping the counter.
2.I use first code for retrieving more values in Bandwidth test function.
Everything returned at each response is available with getArgument(), where you supply the desired value, just as what you’re doing in your modified code.
You don’t need to check the response type every time though - just once before accessing any value. Also, you have two single quotes, which apparently are causing a syntax error. So
<?php
use PEAR2\Net\RouterOS;
include_once 'PEAR2_Net_RouterOS-1.0.0b4.phar';
try {
$client = new RouterOS\Client('192.168.88.98', 'admin', '');
$count = 0;//Count the number of replies we've had.
$client->sendAsync(new RouterOS\Request('/tool bandwidth-test address="192.168.88.99" protocol="udp" direction="both" user="admin" password="" interval=1', null, 't'), function ($response) use (&$count) {
$count++;
if (10 === $count) {
return true;//Cancel after 10 replies. Note that we'd get 2 additional responses, but we won't cancel on them.
}
if ($response->getType() == RouterOS\Response::TYPE_DATA) {
echo $response->getArgument('tx-current') . "\n";
echo $response->getArgument('tx-10-second-average') . "\n";
echo $response->getArgument('rx-current') . "\n";
echo $response->getArgument('rx-10-second-average') . "\n";
}
});
$client->completeRequest('t');
} catch (Exception $e) {
echo 'Unable to connect and/or login to the router';
}
3.Can I use Bandwidth test function from one to multipoint at the same time as shown in figure mpoint.jpg?
4.How to use command?
5.How to write php.code?
Sure. Just send a new request for each router before you begin completing the requests.
Also, if you’re going to treat all routers equally, you might as well put away the function, so that you resupply it to all sendAsync() calls, and put away the command and its common arguments (again, for reusability’s sake). e.g.
<?php
use PEAR2\Net\RouterOS;
include_once 'PEAR2_Net_RouterOS-1.0.0b4.phar';
try {
$client = new RouterOS\Client('192.168.88.98', 'admin', '');
$count = array('99' => 0, '100' => 0, '101' => 0);//Count the number of replies we've had per tag.
$responseHandler = function ($response) use (&$count) {
$count[$response->getTag()]++;
if (10 === $count[$response->getTag()]) {
return true;//Cancel after 10 replies. Note that we'd get 2 additional responses, but we won't cancel on them.
}
if ($response->getType() == RouterOS\Response::TYPE_DATA) {
echo 'Data from "' . $response->getTag() . '":' . "\n";
echo $response->getArgument('tx-current') . "\n";
echo $response->getArgument('tx-10-second-average') . "\n";
echo $response->getArgument('rx-current') . "\n";
echo $response->getArgument('rx-10-second-average') . "\n";
echo "\n";
}
};
$testRequest = new RouterOS\Request('/tool bandwidth-test protocol="udp" direction="both" user="admin" password="" interval=1');
$client->sendAsync(
$testRequest->setArgument('address', '192.168.88.99')->setTag('99'),
$responseHandler
)->sendAsync(
$testRequest->setArgument('address', '192.168.88.100')->setTag('100'),
$responseHandler
)->sendAsync(
$testRequest->setArgument('address', '192.168.88.101')->setTag('101'),
$responseHandler
)->loop();//until all requests are done
} catch (Exception $e) {
echo 'Unable to connect and/or login to the router';
}