CakePHP 3.x. Client API for RouterOS/Mikrotik.

1.0 2016-07-27 09:47 UTC

This package is not auto-updated.

Last update: 2020-05-15 18:44:44 UTC




You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require ivanamat/cakephp3-routeros

Git submodule

git submodule add git@github.com:ivanamat/cakephp3-routeros.git plugins/RouterOs
git submodule init
git submodule update

Manual installation

Download the .zip or .tar.gz file, unzip and rename the plugin folder "cakephp3-routeros" to "RouterOs" then copy the folder to your plugins folder.

Download release

Getting started

Include the RouterOs plugin in app/config/bootstrap.php


Include the RouterOs component in your controller.

    public $components = [
        'RouterOs' => [
            'className' => 'RouterOs.RouterOs'



Set debug mode true/false

    $this->RouterOs->debug = true;


available($host, $port = 8728, $timeout = 1)

Checks connection to the device.

$host Host to connect.
$port Port to connect.
$timeout Router timeout.

return boolean

    if($this->RouterOs->available('')) {

comm($com, $arr = array())

Write (send) data to Router OS.

$com A string with the command to send.
$arr An array with arguments or queries.

return Array with parsed.

    # http://wiki.mikrotik.com/wiki/API_PHP_class
    # example3.php
    $this->RouterOs->comm("/ppp/secret/add", array(
        "name"     => "user",
        "password" => "pass",
        "remote-address" => "",
        "comment"  => "{new VPN user}",
        "service"  => "pptp",

connect($ip, $login, $password)

Login to RouterOS.

$ip Hostname (IP or domain) of the RouterOS server.
$login The RouterOS username
$password The RouterOS password

return boolean

    # http://wiki.mikrotik.com/wiki/API_PHP_class
    if ($this->RouterOs->connect('', 'username', 'password')) {


Save text for debug purposes into log file.

$text Text to write in log file

return void

    # http://wiki.mikrotik.com/wiki/API_PHP_class
    $this->debug('Some text:');
    $data = array(

delete($com, $options = array())

Delete records.

$com A string with the command to send. $options (int/array) '.id' of element or array conditions [key => value].

return boolean

    # Delete item with id 1
    # Delete items with conditions
        'name' => 'MyPool',
        'ranges' => ""]


Close socket connection.

return void


find($path, $options = array())

Make a quick search.

$path A string with the command path to send. Do not include the action (getall, add, set,... ).
$options (int/array) '.id' of element / Array of fields to search as [key => value].

    # Find all interfaces
    $interfaces = $this->RouterOs->find('/interface');
    # Get interface ether1
    $interface = $this->RouterOs->find('/interface', ['name' => 'ether1']);

get($path, $id)

Get element by id.

$path A string with the command path to send. Do not include the action (getall, add, set,... ).
$id Element id.

    $interface = $this->RouterOs->get('/interface', '*1');


Parse response from Router OS.

$response Response data.

return Array with parsed data.

    # http://wiki.mikrotik.com/wiki/API_PHP_class
    # example1.php
    $READ = $this->RouterOs->read(false);
    $ARRAY = $this->RouterOs->parseResponse($READ);

read($parse = true)

Read data from Router OS.

$read Parse the data? default: true

return Array with parsed or unparsed data.

    # http://wiki.mikrotik.com/wiki/API_PHP_class
    # example6.php
    #show me what you got
    $ips = $this->RouterOs->read();

save($path, $options = array())

Write (send) data to Router OS.

$path A string with the command path to send. Do not include the action (getall, add, set,... ).
$options Array of fields [key => value, key => value, ...]. If id is set in the array, the element will be updated.

return On create !trap or new element id. On update empty or !trap.

    # Create new element
        'name' => 'MyRange',
        'ranges' => ""]
    # Update de element.
        '.id' => '*1',
        'name' => 'MyRange',
        'ranges' => ""]

write($command, $param2 = true)

Write (send) data to Router OS.

$command A string with the command to send.
$param2 If we set an integer, the command will send this data as a "tag".
If we set it to boolean true, the funcion will send the comand and finish.
If we set it to boolean false, the funcion will send the comand and wait for next command.
Default: true

return boolean Return false if no command especified.

    # http://wiki.mikrotik.com/wiki/API_PHP_class
    # example3.php
    $ips = array(
    # delete them all !
    foreach($ips as $num => $ip_data) {
     $this->RouterOs->write('/ip/dns/static/remove', false);
     $this->RouterOs->write("=.id=" . $ip_data[".id"], true);

About CakePHP 3.x - RouterOs

This is an adaptation to the CakePHP component from class originally written by Denis Basta.

About RouterOS PHP API class v1.6

MikroTik API PHP

Client API for RouterOS/Mikrotik

This class was originally written by Denis Basta and updated by several contributors. It aims to give a simple interface to the RouterOS API in PHP.

Contributors (before moving to Git)

  • Nick Barnes
  • Ben Menking (ben [at] infotechsc [dot] com)
  • Jeremy Jefferson (http://jeremyj.com)
  • Cristian Deluxe (djcristiandeluxe [at] gmail [dot] com)
  • Mikhail Moskalev (mmv.rus [at] gmail [dot] com)

RouterOS PHP API class v1.6 on Ben Menking GitHub
Mikrotik Wiki page at http://wiki.mikrotik.com/wiki/API_PHP_class


Iván Amat

on GitHub



MIT License