Search by

imafaz / mikrolink

afaztech

Lightweight PHP client for the MikroTik RouterOS API

Package info

github.com/AfazTech/MikroLink

pkg:composer/imafaz/mikrolink

Statistics

Installs: 21

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

v2.0.1 2026-11-29 20:43 UTC

This package is auto-updated.

Last update: 2026-11-29 20:44:49 UTC


README

PHP Version License Version Unit Tests

MikroLink is a lightweight PHP client for managing MikroTik routers through the native RouterOS API.

Features

  • TCP and TLS connections with configurable retries and timeouts
  • Modern and legacy RouterOS authentication
  • API commands, attributes and query parameters
  • Automatic binary word framing and response parsing
  • Detection of incomplete replies and socket failures
  • PSR-3 logging with optional logger injection and no logging by default

Requirements

  • 64-bit PHP >= 8.0
  • Composer
  • OpenSSL support for TLS connections
  • An accessible RouterOS API service

Installation

composer require afaztech/mikrolink

The Composer package is now published as afaztech/mikrolink; the PHP namespace remains unchanged. Features described here reflect the main branch.

Quick Start

<?php

require __DIR__ . '/vendor/autoload.php';

use MikrotikApi\MikroLink;

$password = getenv('ROUTEROS_PASSWORD');
if ($password === false || $password === '') {
    throw new RuntimeException('Set ROUTEROS_PASSWORD.');
}

$router = new MikroLink(5);

try {
    if (!$router->connect('router.example.com', 'api-user', $password, 8729, true)) {
        throw new RuntimeException('RouterOS connection failed.');
    }

    print_r($router->exec('/interface/print'));
} finally {
    $router->disconnect();
}

Logging

MikroLink uses PSR-3 and defaults to Psr\Log\NullLogger. No log files are created automatically.

Pass any PSR-3 logger (for example a Monolog or application logger):

$router = new MikroLink(logger: $logger);

Existing calls using only timeout, attempts and delay are unchanged. The former logFile and printLog constructor arguments are removed; configure file or console logging in your injected logger instead.

Documentation

See DOCUMENT.md for configuration, API methods, queries, response formats, security and troubleshooting.

Contributing

Open an issue or submit a focused pull request with relevant tests. Run the unit suite locally:

composer install
composer test

License

Licensed under the MIT License.