imafaz / mikrolink
Lightweight PHP client for the MikroTik RouterOS API
Requires
- php: >=8.0
- php-64bit: >=8.0
- psr/log: ^1.1 || ^2.0 || ^3.0
Requires (Dev)
- phpunit/phpunit: ^9.6 || ^10.5 || ^11.5 || ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
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.