-
-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Troubles with foreach #2
Comments
Hello and thanks for your report! foreach ($arr as $ip) {
if (false === filter_var($ip, FILTER_VALIDATE_IP)) {
continue;
}
$query = new Query('/queue/simple/print');
$query->add('?target=' . $ip . '/32');
$responses = $ros->write($query)->read();
print_r($responses);
echo "<hr>";
sleep(1);
} Today (after work) I planned to release a new version of the library. which contains a few of changes that improve the readability of the code. If solution with |
Hello, thank u for fast reaction :) |
Hi @temandroid!
Yep, I think you need to play with 'timeout' parameter of API client, look at this example. Unfortunately I couldn't reproduce your problem on my router (I've tried to run 100 parallel scripts in same time), maybe you can send me your queue table as an example? Btw, what is version of RouterOS which you use on your device? |
Hmm, in your example i receiving an array of all queues, not filtered by target... $ips=array ();
for ($i=2; $i <= 128; $i++) {
array_push($ips, '10.50.0.'.$i);
}
$conn=(new Config())->set('timeout', 1)->set('host', '127.0.0.1')->set('user', 'admin')->set('pass', 'admin');
$ros=new Client($conn);
foreach ($ips as $ip) {
echo $ip."<br>";
$query=new Query('/queue/simple/print');
$query->add('?target='.$ip.'/32');
$response=$ros->write($query)->read();
print_r($response);
echo "<hr>";
} |
Wow, that's a very strange! Looks like a bug with API socket in RouterOS. Probaly just need add yet another call of read method, try this: $ips=array ();
for ($i=2; $i <= 128; $i++) {
array_push($ips, '10.50.0.'.$i);
}
$conn=(new Config())->set('timeout', 1)->set('host', '127.0.0.1')->set('user', 'admin')->set('pass', 'admin');
$ros=new Client($conn);
foreach ($ips as $ip) {
echo $ip."<br>";
$query=new Query('/queue/simple/print');
$query->add('?target='.$ip.'/32');
$response=$ros->write($query)->read();
print_r($response);
echo "<hr>";
// Add this
$ros->read();
} |
I tried, and as a result I was stuck on an IP which is not in the queue... $request=new PEAR2\Net\RouterOS\Request('/queue/simple/print');
$query=PEAR2\Net\RouterOS\Query::where('target', $ip.'/32');
$request->setQuery($query);
$responses=$ros->sendSync($request);
print_r($responses); So, I don't think that is a bug |
Found it ! |
Sounds good. nice work! |
ROS 7 ? ;)
|
No)) On release page, like 0.8.2 :) |
In
as result have answers like
Array ( [after] => Array ( [] => ) )
So new query was exec so fast as I understand...
For now I move
$ros=new Client($con);
inside foreach and it work, but it's not good, of course, and so slow...The text was updated successfully, but these errors were encountered: