• MikroTik.com
  • RouterBOARD
  • User Meeting
  • Training
  • User Manual
  • Support
  • Downloads
  • Videos
Register |   * Login | HOME

View unanswered posts | View active topics

[API suggestion] "Keep alive" command/argument  Page 1 of 1
 [ 3 posts ]  Post new topic Reply to topic
  Print view Previous topic | Next topic 
Author Message
boen_robot
 Post subject: [API suggestion] "Keep alive" command/argument
PostPosted: Sat Mar 03, 2012 6:31 pm 
Online
Long time Member
Long time Member
User avatar

Joined: Thu Aug 31, 2006 3:43 pm
Posts: 535
Karma: 79

Location: europe://Bulgaria/Plovdiv
In languages like PHP, where the application must explicitly start to listen to the server and fail if it receives nothing in a certain timeout, using commands like "listen" can cause the connection to break unless listen produces something in the timeout interval.

To remedy this problem currently, clients need to send a continious ping command to keep the connection busy while they "listen". This however entails an unnecesary performance penalty, since the ping itself isn't really necessary - any data would do, as long as it is available within the timeout interval.

A more efficient solution would be to have a dedicated command that sends an empty !re reply at a certain specified interval OR if the listen command does that if an optional argument with an interval is specified (since the listen command is really where the problem is). Personally, I'd prefer the latter, but I'll be happy with the first too.

e.g.
Code:
/ip/arp/listen
.tag=arp
=keep-alive-interval=2s


would return (after 4s, if nothing happens during that time):
Code:
!re
.tag=arp

!re
.tag=arp


or if something (in this case a deleted item) has happened within that time:
Code:
!re
.tag=arp

!re
.tag=arp
=.id=*68
=.dead=yes

!re
.tag=arp


_________________
PEAR2_Net_RouterOS(1.0.0b3) - My API client in PHP


Top
 Profile  
 
janisk
 Post subject: Re: [API suggestion] "Keep alive" command/argument
PostPosted: Mon Mar 05, 2012 9:20 am 
Offline
MikroTik Support
MikroTik Support
User avatar

Joined: Tue Feb 14, 2006 9:46 am
Posts: 4811
Karma: 37

Location: Riga, Latvia
you have to change that in PHP as there are no such issues with sockets. That should be configurable in PHP settings as that deviates from experience on all languages i know of. Technically TCP connection should be opened and never closed unless one of the ends imposes some artificial timeout value. Take for example SSH client connections - stays opened for weeks.

you can look here:
http://php.net/manual/en/function.strea ... imeout.php

also, if any other php setting fail you can send non-existing command to the router. It will kick the parser and reply that command does not exist. To be sure send md5 sum of some string as such command most probably will not be intreoduced into RouterOS

Code:
/22083539850d5fc8428146d7f76a135d


Code:
!trap
=category=0
=message=no such command or directory (22083539850d5fc8428146d7f76a135d)

!trap
=message=no such command

!done


an


Top
 Profile  
 
boen_robot
 Post subject: Re: [API suggestion] "Keep alive" command/argument
PostPosted: Mon Mar 05, 2012 2:40 pm 
Online
Long time Member
Long time Member
User avatar

Joined: Thu Aug 31, 2006 3:43 pm
Posts: 535
Karma: 79

Location: europe://Bulgaria/Plovdiv
I'm aware of the stream_set_timeout() function, but that still terminates the connection if no data is received within the specific timeout. Sure, you can set the timeout to something long, but that's still a connection being terminated after that long time.

And during that receiving attempt, one can't send additional data until the receiving stops. To be more precise, one can't do anything, as the fread() function doesn't return until at least one packet is received (or there is something remaining in PHP's buffer). So sending non-existing commands isn't really possible.

I'll look into non blocking streams. Perhaps that will help. It will surely start to feel unnatural though.

Thanks.

_________________
PEAR2_Net_RouterOS(1.0.0b3) - My API client in PHP


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  Page 1 of 1
 [ 3 posts ] 

Board index » RouterOS » Scripting

All times are UTC + 2 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Karma functions powered by Karma MOD © 2007, 2009 m157y