Download the PHP package ocolin/routeros without Composer

On this page you can find all versions of the php package ocolin/routeros. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package routeros

Packagist Version PHP Version License Downloads

RouterOS

A PHP 8.4 client for the MikroTik RouterOS API.

This library provides a clean, modern interface for communicating with MikroTik RouterOS devices via their API protocol. Built with a layered architecture, it handles the low-level binary protocol details so you can focus on managing your network infrastructure. Features include a fluent query builder, SSL support, environment variable configuration, and a comprehensive test suite.


Table of Contents


Requirements


Installation


Quick Start


Configuration

The client can be configured by passing an associative array, a Config object, or any object whose properties match the configuration parameters. The array approach is the most common and concise.

Parameters

Parameter Type Default ENV Variable Description
host string required ROUTEROS_HOST IP address or hostname of device
username string admin ROUTEROS_USERNAME Username to authenticate with
password string '' ROUTEROS_PASSWORD Password to authenticate with
ssl bool false ROUTEROS_SSL Enable SSL connection
port int 8728 ROUTEROS_PORT Port for non-SSL connections
sslPort int 8729 ROUTEROS_SSL_PORT Port for SSL connections
timeout int 10 ROUTEROS_TIMEOUT Connection timeout in seconds
socketTimeout int 30 ROUTEROS_SOCKET_TIMEOUT Response timeout in seconds
sslVerify bool false ROUTEROS_SSL_VERIFY Verify SSL certificate

Using an Array

Using a Config Object

Environment Variables

Environment variables can be used instead of passing configuration directly. The ENV variable names are listed in the parameters table above.

Prefix Support

To support multiple devices, an optional prefix can be used:


Basic Usage

There are three methods that can be used for inputting data to a device. A simple string command, an array of command words, or a Command object which provides methods for more complex queries.

String input

This is good for simple single command queries that don't require any special conditions.

Example

Array input

Useful for advanced users who prefer working directly with the API syntax, or for sending commands not yet supported by the Command builder.

Example

Command Object Input

A Command object is included for making complex queries easier to type doesn't require that you know the API syntax.

Example


Query Builder

The Command class allows you to create complex queries with a simple syntax. The Query takes one argument for the constructor, which is the RouterOS command word.

In this example we are sending a simple command with no other parameters. The command word is always required by RouterOS.

Attribute

The attribute method allows you to specify attributes to your query. This is useful when creating and modifying an object on the Mikrotik device. Each attribute has a name and a value. RouterOS uses "yes" and "no" for boolean attributes, but this client will automatically convert boolean for you.

Query

The query method allows you to filter the results of your query.

Query Arguments

One way to add a query is by just using the constructor arguments. This is a means to manually enter the data without any helped functions.

Equals

This function takes a single value and which the key value must be equal to.

lessThan

This function takes a single value which the key value must be less than.

greaterThan

This function takes a single value which the key value must be greater than.

exists

Include if a property exists for the return results.

notExists

Include if a property does not exist.

Logical Operators

When using multiple queries, you can specify a logical operator to indicate if all the queries should be met, or if any should be met, or it they should not be met.

The logical operator must always come after your query parameters for RouterOS to understand it.

And Operator

The and operator requires that all query parameters must be met. This is also the default operator so does not need to be specified.

Or Operator

The or operator requires any of the query parameters to be met.

Not Operator

This operator says to filter results to not contain the previous query parameter. Unlike AND and OR, this operator can be used prior to the end and can be specified for each query paramater.

Proplist

The proplist allows you to limit the columns that are returned in your results.

Tags

Tag IDs can be added to queries.

Aliases

There are a few alias functions which exist for those using method names found in other libraries.

Where

The where method is an alias for the query method.

Equal

The equal method is an alias for the attribute method.

Operations

The operations method is an alias for the logical operator methods, using the same syntax as routeros-api-php.


Streaming

Some RouterOS commands return a continuous stream of data rather than a single response. The most common example is the /interface/listen command which sends updates whenever an interface changes state. The stream() method handles these commands by returning a Generator that yields results one at a time as they arrive.

Unlike query() which collects all results and returns them as an array, stream() never stops on its own — it will keep yielding results until you break out of the loop or the connection is closed.

The stream() method accepts the same input types as query() — a string command, an array of words, or a Command object.

Note: To gracefully stop a streaming command, break out of the loop. Explicit command cancellation using /cancel will be available in a future release when concurrent command support is added.


SSL

The client supports SSL connections using RouterOS's secure API service. SSL is disabled by default and must be enabled in your configuration.

RouterOS Setup

Before enabling SSL in the client, the api-ssl service must be configured on your RouterOS device. A certificate is required.

Generate a self-signed certificate directly on the router:

Then allow connections by setting the allowed address under IP → Services → api-ssl.

Client Configuration

Note: Most RouterOS devices use self-signed certificates. Set sslVerify to false unless you have installed a trusted certificate on your device.


Laravel Integration

This package includes a Service Provider for easy integration with Laravel applications.

Laravel Installation

Require the Laravel support package:

The Service Provider will be automatically discovered by Laravel.

Laravel Configuration

Publish the configuration file:

This creates config/routeros.php in your Laravel application. Update your .env file with your device credentials: ROUTEROS_HOST=192.168.88.1 ROUTEROS_USERNAME=admin ROUTEROS_PASSWORD=secret

Laravel Usage

The Client is automatically registered in Laravel's service container and can be injected into your controllers, services, or jobs:


Migrating from routeros-api-php

This library was designed as a maintained alternative to the widely used but unmaintained routeros-api-php library. Several alias methods are included to ease migration.

Method Aliases

routeros-api-php ocolin/routeros Notes
->where() ->query() Alias included
->equal() ->attribute() Alias included
->operations('\|') ->or() Alias included
->operations('&') ->and() Alias included
->operations('!') ->not() Alias included
->tag() Coming in v2 Not yet implemented

Configuration Differences

The client is configured using an array or Config object rather than separate setter methods. The parameter names are similar but not identical:

routeros-api-php ocolin/routeros
host host
user username
pass password
port port
ssl ssl
timeout timeout
socket_timeout socketTimeout

Roadmap

The following features are planned for future releases:

License

This project is licensed under the MIT License. See the LICENSE file for details.


All versions of routeros with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ocolin/global-type Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ocolin/routeros contains the following files

Loading the files please wait ...