0

I am trying to communicate with a Mikrotik Router OS Via PHP as below

 private function openSocket(): void
    {
        $options = ['ssl' => $this->config('ssl_options')];
        $context = stream_context_create($options);
        $proto = $this->config('ssl') ? 'ssl://' : '';
        $socket = @stream_socket_client(
            $proto . $this->config('host') . ':' . $this->config('port'),
            $this->socket_err_num,
            $this->socket_err_str,
            $this->config('timeout'),
            STREAM_CLIENT_CONNECT,
            $context
        );
        if ($socket === false) {
            throw new ConnectException('Unable to establish socket session, ' . $this->socket_err_str);
        }
        stream_set_timeout($socket, $this->config('timeout'));
        $this->setSocket($socket);
    }

Here, the PORT is one of public const PORT = 8728; public const PORT_SSL = 8729;. and The IP address is 192.168.0.1

Connection worked flawlessly on localhost.

Now when I tried to access the RouterOS from a php script hosted on an online server I am constantly getting the error Unable to establish socket session, No route to host from the php script.

Please, how can I resolve this.

Any help would be highly appreciated.

user15155716
  • 153
  • 6

0 Answers0