$addRequest = new Request('/ip/firewall/address-list/print');
$addRequest->setArgument('follow', '1');
$addRequest->setTag('adr');
$client->sendAsync($addRequest);
it has same problem . the last line will not finish . i want an always running code and use the data received from router .
each time something adds or removes from specified address-lists the script should do the same in another router in near realtime
“follow” turns “print” into an interactive command, and interactive commands are not available over the API protocol.
To do what you want, you can use the “listen” command instead, e.g.
$listenRequest = new Request('/ip/firewall/address-list/listen');
$listenRequest->setTag('adr');
$client->sendAsync($listenRequest);
It’s important to note however, that with both PHP clients currently, if your connection remains idle for default_socket_timeout seconds (i.e. you start receiving with loop() or completeRequest(), but no data arrives in that time), it will be terminated.
I plan to change that in my client later on, but in the meantime, as a workaround, you can put out a ping command that runs every “default_socket_timeout - 1” seconds, thus avoiding the disconnect, e.g.
$listenRequest = new Request('/ip/firewall/address-list/listen');
$listenRequest->setTag('adr');
$client->sendAsync($listenRequest);
$pingRequest = new Request('/ping address=127.0.0.1 .proplist', null, 'p');
$pingRequest->setArgument('interval', ini_get('default_socket_timeout') - 1);
$client->sendAsync($pingRequest);
//execute loop() or completeRequest() here