Hello guys,
I have a problem with my MikroTik configuration.
I would like to connect the Pear2RouterOS API PHP via website to access the local routerOS(IP: 192.168.0.15)
I just want to connect and create a user, edit, delete using a website platform to send or sync data to webfig/winbox control.
Here’s my sample code that I used:
<?php use PEAR2\Net\RouterOS; require_once 'PEAR2_Net_RouterOS-1.0.0b5.php'; try { $client = new RouterOS\Client('192.168.0.15', 'admin', ''); echo 'OK'; } catch (Exception $e) { die($e); } When I try to run this script from my localhost. The code is working properly. Then I got an error after I run it to my web hosting. Here's the error: exception 'PEAR2\Net\Transmitter\SocketException' with message 'stream_socket_client(): unable to connect to tcp://192.168.0.15:8728/admin%2F (Connection timed out)' in phar:///var/www/html/PEAR2_Net_RouterOS-1.0.0b5.php/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/Transmitter/TcpClient.php:205 Stack trace: #0 phar:///var/www/html/PEAR2_Net_RouterOS-1.0.0b5.php/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/Transmitter/Stream.php(130): PEAR2\Net\Transmitter\TcpClient->createException('stream_socket_c...', 0) #1 [internal function]: PEAR2\Net\Transmitter\Stream->handleError(2, 'stream_socket_c...', 'phar:///var/www...', 147, Array) #2 phar:///var/www/html/PEAR2_Net_RouterOS-1.0.0b5.php/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/Transmitter/TcpClient.php(147): stream_socket_client('tcp://192.168.0...', 110, 'Connection time...', '60', 4, Resource id #2) #3 phar:///var/www/html/PEAR2_Net_RouterOS-1.0.0b5.php/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/RouterOS/Communicator.php(148): PEAR2\Net\Transmitter\TcpClient->__construct('192.168.0.15', 8728, false, NULL, 'admin/', '', NULL) #4 phar:///var/www/html/PEAR2_Net_RouterOS-1.0.0b5.php/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/RouterOS/Client.php(146): PEAR2\Net\RouterOS\Communicator->__construct('192.168.0.15', 8728, false, NULL, 'admin/', '', NULL) #5 /var/www/html/routeros.php(6): PEAR2\Net\RouterOS\Client->__construct('192.168.0.15', 'admin', '') #6 {main} Next exception 'PEAR2\Net\Transmitter\SocketException' with message 'Failed to connect with socket.' in phar:///var/www/html/PEAR2_Net_RouterOS-1.0.0b5.php/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/Transmitter/TcpClient.php:205 Stack trace: #0 phar:///var/www/html/PEAR2_Net_RouterOS-1.0.0b5.php/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/Transmitter/TcpClient.php(163): PEAR2\Net\Transmitter\TcpClient->createException('Failed to conne...', 8, Object(PEAR2\Net\Transmitter\SocketException)) #1 phar:///var/www/html/PEAR2_Net_RouterOS-1.0.0b5.php/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/RouterOS/Communicator.php(148): PEAR2\Net\Transmitter\TcpClient->__construct('192.168.0.15', 8728, false, NULL, 'admin/', '', NULL) #2 phar:///var/www/html/PEAR2_Net_RouterOS-1.0.0b5.php/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/RouterOS/Client.php(146): PEAR2\Net\RouterOS\Communicator->__construct('192.168.0.15', 8728, false, NULL, 'admin/', '', NULL) #3 /var/www/html/routeros.php(6): PEAR2\Net\RouterOS\Client->__construct('192.168.0.15', 'admin', '') #4 {main} Next exception 'PEAR2\Net\RouterOS\SocketException' with message 'Error connecting to RouterOS' in phar:///var/www/html/PEAR2_Net_RouterOS-1.0.0b5.php/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/RouterOS/Communicator.php:150 Stack trace: #0 phar:///var/www/html/PEAR2_Net_RouterOS-1.0.0b5.php/PEAR2_Net_RouterOS-1.0.0b5/src/PEAR2/Net/RouterOS/Client.php(146): PEAR2\Net\RouterOS\Communicator->__construct('192.168.0.15', 8728, false, NULL, 'admin/', '', NULL) #1 /var/www/html/routeros.php(6): PEAR2\Net\RouterOS\Client->__construct('192.168.0.15', 'admin', '') #2 {main} Please I need help for this. Thank you, Sapphire