Community discussions

MikroTik App
 
rssreader
just joined
Topic Author
Posts: 6
Joined: Mon Jul 03, 2017 3:57 pm

Why command "fetch" doesn't wait for output?

Wed Apr 15, 2020 11:54 am

I use the "fetch" command to run PHP scripts on my web server using a URL call. PHP script generates large data (XML) - it takes a long time. The output is only "OK" when finished.
However, the fetch command does not wait for "OK". Is it possible to set a timeout for fetching output or how to solve it?
I need verify that "OK" has been returned.
 
andriys
Forum Guru
Forum Guru
Posts: 1526
Joined: Thu Nov 24, 2011 1:59 pm
Location: Kharkiv, Ukraine

Re: Why command "fetch" doesn't wait for output?

Wed Apr 15, 2020 12:22 pm

However, the fetch command does not wait for "OK".
It does. You don't see it in console because the result goes to file by default. RTFM here, please: Tools/Fetch.
As to checking what was returned, read this section specifically: Return value to a variable.
 
rssreader
just joined
Topic Author
Posts: 6
Joined: Mon Jul 03, 2017 3:57 pm

Re: Why command "fetch" doesn't wait for output?

Wed Apr 15, 2020 11:08 pm

Of course I know that. That's not the problem. Here is my code:
:local cronFile "result.log";
:local cronUrl "https://www.xxxxxxx.xx/xxxxxxxxxxxxx.php";
:tool fetch url=$cronUrl dst-path=$cronFile;
:local cronResult [/file get $cronFile contents];
:if ( $cronResult != "OK") do={ /tool e-mail send to="email@email.xx" subject="cron incomplete" body=$cronResult file=$cronFile }
Calling "fetch" terminates execution rest of the script, no record in the system log ... nothing
just end
PHP script finishes the job and returns "OK", but "fetch" dies in the meantime
 
creatin
Member Candidate
Member Candidate
Posts: 108
Joined: Sat Nov 23, 2019 2:59 am

Re: Why command "fetch" doesn't wait for output?

Fri Apr 17, 2020 10:25 am

Try to put a delay of 5 seconds before and 10 seconds after fetch command
 
rssreader
just joined
Topic Author
Posts: 6
Joined: Mon Jul 03, 2017 3:57 pm

Re: Why command "fetch" doesn't wait for output?

Wed Jul 01, 2020 8:32 am

like this ?:
:local cronFile "result.log";
:local cronUrl "https://www.xxxxxxx.xx/xxxxxxxxxxxxx.php";
:delay 5s;
:tool fetch url=$cronUrl dst-path=$cronFile;
:delay 10s;
:local cronResult [/file get $cronFile contents];
:if ( $cronResult != "OK") do={ /tool e-mail send to="email@email.xx" subject="cron incomplete" body=$cronResult file=$cronFile }
The same result - nothing.
The fetch command is missing a "timeout" option.
 
sutrus
Frequent Visitor
Frequent Visitor
Posts: 58
Joined: Fri Jun 30, 2017 11:27 pm

Re: Why command "fetch" doesn't wait for output?

Wed Jul 01, 2020 8:26 pm

Return value to a variable:

:local cronUrl "https://www.xxxxxxx.xx/xxxxxxxxxxxxx.php";
:local result [/tool fetch url=$cronUrl as-value output=user];
:if ($result->"status" = "finished") do={
:if ($result->"data" != "OK") do={ /tool e-mail send to="email@email.xx" subject="cron incomplete" body=$cronResult file=$cronFile }
}
 
rssreader
just joined
Topic Author
Posts: 6
Joined: Mon Jul 03, 2017 3:57 pm

Re: Why command "fetch" doesn't wait for output?

Sun Mar 07, 2021 3:56 pm

it also doesn't work
only "start" appears in the log:
:local cronUrl "https://xxxxxxxxxxxxx.php";
:log info "start";
:local result [ :tool fetch url=$cronUrl as-value output=user ];
:log info "finish";
 
elico
Member Candidate
Member Candidate
Posts: 143
Joined: Mon Nov 07, 2016 3:23 am

Re: Why command "fetch" doesn't wait for output?

Tue Mar 23, 2021 10:38 pm

You should try to see if there is some kind of error using a do and on-error like:
:local cronUrl "https://xxxxxxxxxxxxx.php";
/log info "start";
:do { 
	/tool fetch url=$cronUrl;
} on-error={
	/log info "finished with error";
}
/log info "finished";
The log and fetch should start with "/" in scripts.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Why command "fetch" doesn't wait for output?

Wed Mar 24, 2021 8:23 am

You do not need the ; after each line.
Its only needed when there are more than one command at the same line.
 
Chupakabra303
just joined
Posts: 14
Joined: Tue Jun 20, 2017 3:07 pm

Re: Why command "fetch" doesn't wait for output?

Tue Dec 21, 2021 4:32 pm

Mikrotik team, please add timeout option for Fetch tool!
Default timeout 10 (?) second is too small for specific tasks

failure: connection timeout
 
infabo
Long time Member
Long time Member
Posts: 617
Joined: Thu Nov 12, 2020 12:07 pm

Re: Why command "fetch" doesn't wait for output?

Wed Dec 29, 2021 1:25 pm

@rssreader have you found a solution? I have the same issue, where nothing after tool/fetch is executed in a script.
 
User avatar
byosni
just joined
Posts: 1
Joined: Thu Oct 22, 2009 4:13 pm
Location: Brasil

Re: Why command "fetch" doesn't wait for output?

Thu Jan 27, 2022 10:08 pm

Eu também tenho o mesmo problema, @mikrotik coloque um "limit timeout" no tool fetch

Who is online

Users browsing this forum: No registered users and 19 guests