Closed genysta closed 2 years ago
I got gateway error after waiting a few minutes
Hello! Please read this for details about similar issues: https://github.com/EvilFreelancer/routeros-api-php#unable-to-establish-socket-session-operation-timed-out
And also need to check if IP of router is available and port is open from server where installed the library: https://en.wikipedia.org/wiki/Nmap
nmap ip_address -p api_port
it's available and open and i got log logged in from api. And i've tried adding count-only parameter and get a response
Currently im trying to print ip address from router with just 3 ip address and it works perfectly
Hm, interesting, can you try to print response from command like this:
$response = $client->query('/ip/address/print')->read(false);
var_dump($response);
->read(false)
will turn off parsing of response, in some cases in will contain response with details about error from router side.
Ah, by the way, which version of RouterOS you use?
I'll let you know later, i've tried it on 6.44.6 and 6.47.9
i've tried ->read(false)
and it's still the same, return nothing. My RouterOS version is 6.47.9
@genysta hello! Can you please provide sample of code which you use for connecting to RouterOS API?
@EvilFreelancer of course, here's my code
$client = new Client([
'host' => '10.10.10.1',
'user' => 'someuser',
'pass' => 'somepass'
]);
$response = $client->query('/ip/address/print')->read();
var_dump($response);
It looks like the most basic example, but in any way I tried different ways of working with the library, I think you need to enable advanced debugging mode and check the logs.
Need to add error_reporting(E_ALL);
into to top of your script then re-run it again.
I guess reproduced your issue, for example, I have prepared everything for deployment on my local PC, then added these sources to Docker image without one of the required extensions, like ext-sockets
. And also see nothing in response, but in logs i have also see error message about missed extension.
Im using Laravel command to test it and added error_reporting(E_ALL);
on top of my script and it's still return nothing. It's possible if there's something i missunderstand because im new to Laravel and php.
Check Laravel logs in storage
folder from root of project.
Log file will looks like laravel_2021-09-27.log
or just laravel.log
.
After running command need to look at the errors which occurs on script execution stage, use tail -f laravel.log
for logs obtaining reading process.
Ah, plus need to check for extension, try to run php -m
in response must be sockets
line, if you don't see it then need to install.
on laravel.log there's nothing i see when i run my command, and for php -m
there's sockets
line
Okay, then need to check simple solution, need to create a simple script in root of project, eg test.php
with following content:
<?php
error_reporting(E_ALL);
require_once __DIR__ . '/vendor/autoload.php';
$client = new \RouterOS\Client([
'host' => '10.10.10.1',
'user' => 'someuser',
'pass' => 'somepass'
]);
$response = $client->query('/ip/address/print')->read();
var_dump($response);
Then run it php -f test.php
and check response.
If you will receive response from router then issue somewhere in your Laravel installation.
Tried test.php
and it still give me nothing. And i've tried it on other project and still give me nothing.
@genysta please write to me via email (it will visible in my profile), i'll send you instruction of how to communicate with me via Telegram.
@EvilFreelancer sent email to email address on your profile
So i've tried it on another machine and it works properly so i guess there's something wrong with my PHP
The required extension is enabled, is there any way to check what's missing from my php installation?
@EvilFreelancer After downgrading to php 7.4 i got Stream timed out
on router with 10 ip addresses but it works on router with less than 10 ip addresses. Did i miss something?
The problem is on my php installation
Hi @genysta can u mention the problem on ur PHP installation? seems I got the same issue
Hi @genysta can u mention the problem on ur PHP installation? seems I got the same issue
Hi, sorry but i start with fresh installation without further investigation on my PHP installation. Sorry but i dont know the problem.
Hello, im trying to get ip addresses from my router but when i run the query it returns nothing. On the router log it just logged in from api log, did i miss something? Here's my code, im trying the same code from the doc but it's the same
$response = $client->query('/ip/address/print')->read();