Net_RouterOS icon indicating copy to clipboard operation
Net_RouterOS copied to clipboard

Persistent connection

Open luizsilva-dev opened this issue 4 years ago • 3 comments
trafficstars

I did not understand how to use the persistent connection. I activated the 5th element and it is generating the persistentId. But how do I access the API without it opening a new connection?

luizsilva-dev avatar Mar 20 '21 15:03 luizsilva-dev

A connection is still created once when the PHP process starts and persists until the PHP process closes.

How many requests you can handle with the same connection depends on your web server config.

If you are running PHP as an apache module f.e., then PHP is tied to Apache's process, so the connection will only be gone if you restart Apache.

In the case of FastCGI, there's a "recycle" time and number of requests. Whenever a "recycle" occurs, persistent data is lost.

boenrobot avatar Mar 20 '21 17:03 boenrobot

I use Apache module. So it means that the connection remains open until Apache is restarted. Even so, whenever I make a request, a new connection is initiated with mikrotik (but not closed). What I need is for a function to start the connection with mikrotik and when I have a new request, it should be done with the connection that is already open. How do I save this open connection for use in subsequent requests?

ie:

$RadiusServer = new RouterOS\Client('ip', 'user', 'pass', null, true);
$connection = $RadiusServer->persistentId;

if($connection){
  $util = new RouterOS\Util($connection);
  $util->setMenu('/ip arp');
  print_r($util->getAll());
}

luizsilva-dev avatar Mar 20 '21 18:03 luizsilva-dev

There is no persistentId property, so how are you getting that?

Anyway... I'm not entirely sure why that happens. Can you give me your versions involved? Apache version, PHP version, APC(u) version, MikroTik version, OS version? Any one of those could be the cause, as persistent connections are kind of a hack job to be honest.

boenrobot avatar Mar 20 '21 21:03 boenrobot