Exemplo n.º 1
0
 public function testListenOverTimeout()
 {
     $this->object->sendAsync(new Request('/queue simple listen', null, 'l'), function ($response) {
         PHPUnit_Framework_Assert::assertFalse($response);
     });
     $this->assertSame(1, $this->object->getPendingRequestsCount());
     $this->assertTrue($this->object->loop(ini_get('default_socket_timeout') + 3));
     $this->assertSame(1, $this->object->getPendingRequestsCount());
     $this->assertSame(array(), $this->object->extractNewResponses('l')->toArray());
 }
Exemplo n.º 2
0
 public function testCancellingSeparation()
 {
     $client = new Client(\HOSTNAME, USERNAME, PASSWORD, PORT, true);
     $pingRequest = new Request('/ping', null, 'ping');
     $pingRequest->setArgument('address', Test\HOSTNAME);
     $this->object->sendAsync($pingRequest);
     $client->sendAsync($pingRequest);
     $client->loop(2);
     $this->object->loop(2);
     $this->assertGreaterThan(0, count($client->extractNewResponses('ping')));
     $this->assertGreaterThan(0, count($this->object->extractNewResponses('ping')));
     unset($client);
     $this->object->loop(2);
     $this->assertGreaterThan(0, count($this->object->extractNewResponses('ping')));
 }
<?php

use PEAR2\Net\RouterOS;
require_once 'PEAR2/Autoload.php';
$client = new RouterOS\Client('192.168.0.1', 'admin');
$addRequest = new RouterOS\Request('/ip/arp/add');
$addRequest->setArgument('address', '192.168.0.100');
$addRequest->setArgument('mac-address', '00:00:00:00:00:01');
$addRequest->setTag('arp1');
$client->sendAsync($addRequest);
$addRequest->setArgument('address', '192.168.0.101');
$addRequest->setArgument('mac-address', '00:00:00:00:00:02');
$addRequest->setTag('arp2');
$client->sendAsync($addRequest);
foreach ($client->completeRequest('arp1') as $response) {
    if ($response->getType() === Response::TYPE_ERROR) {
        echo "Error response for 'arp1'!\n";
    }
}
foreach ($client->completeRequest('arp2') as $response) {
    if ($response->getType() === Response::TYPE_ERROR) {
        echo "Error response for 'arp2'!\n";
    }
}
echo 'OK';
<?php

use PEAR2\Net\RouterOS;
require_once 'PEAR2/Autoload.php';
$client = new RouterOS\Client('192.168.0.1', 'admin');
//Custom function, defined specifically for the example
$responseHandler = function ($response) {
    if ($response->getType() === Response::TYPE_FINAL) {
        echo "{$response->getTag()} is done.\n";
    }
};
$addRequest = new RouterOS\Request('/ip/arp/add');
$addRequest->setArgument('address', '192.168.0.100');
$addRequest->setArgument('mac-address', '00:00:00:00:00:01');
$addRequest->setTag('arp1');
$client->sendAsync($addRequest, $responseHandler);
$addRequest->setArgument('address', '192.168.0.101');
$addRequest->setArgument('mac-address', '00:00:00:00:00:02');
$addRequest->setTag('arp2');
$client->sendAsync($addRequest, $responseHandler);
$client->loop();
//Example output:
/*
arp1 is done.
arp2 is done.
*/