Skip to content
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

exec() problem #71

Open
vbutaev opened this issue Mar 7, 2021 · 2 comments
Open

exec() problem #71

vbutaev opened this issue Mar 7, 2021 · 2 comments
Labels

Comments

@vbutaev
Copy link

vbutaev commented Mar 7, 2021

need your help again please: why this code doesn't work? in routerOS terminal is everything fine

try {
	$util->exec(
	    '
	:foreach v in=[find list="test"] do={
	    :do {
	        remove=$v;
	    } on-error={
	        :error ("failed to remove " . $v);
	    };
	};
	    '
	);
} catch (RouerOS\RouterErrorException $e) {

}
@boenrobot
Copy link
Member

boenrobot commented Mar 7, 2021

You can get error details by analyzing the exception. You can just echo the whole variable to get the whole thing.

In this case, I'm thinking it's remove $v not remove=$v. Idk how that went through in terminal. It shouldn't go there either.

Removing/disabling/enabling all items in a list can be made much more efficient if you just give the results of find to a single call. In scripting, that would be
remove [find list="test"]

And in API
$util->remove($util->find(RouerOS\Query('list', 'test')));

If you're doing more things in the exec than that one remove or the list is so big that it's transfer to PHP would be too much, you should use exec(). For smaller lists, it would be more efficient to do the 2 API calls of find and remove than the 3 calls of add, run and remove. Exactly where the line between "smaller" and "bigger" lists is, I don't know, as I haven't done benchmarks. Intuitively, I'd guess somewhere around 4k items maybe.

@vbutaev
Copy link
Author

vbutaev commented Mar 7, 2021

thank you, remove $v was the reason, and script is stable when :log warning(); is set

try {
	$util->exec(
	'
        :foreach v in=[find list="'.$listNameToExport[$i].'"] do={
		:do {
			remove $v;
		} on-error={
		       :log warning ("php: failed to remove " . $v);
		};
	};
	 '
	);
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants