Page 1 of 1
Why command "fetch" doesn't wait for output?
Posted: Wed Apr 15, 2020 11:54 am
by rssreader
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.
Re: Why command "fetch" doesn't wait for output?
Posted: Wed Apr 15, 2020 12:22 pm
by andriys
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.
Re: Why command "fetch" doesn't wait for output?
Posted: Wed Apr 15, 2020 11:08 pm
by rssreader
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
Re: Why command "fetch" doesn't wait for output?
Posted: Fri Apr 17, 2020 10:25 am
by creatin
Try to put a delay of 5 seconds before and 10 seconds after fetch command
Re: Why command "fetch" doesn't wait for output?
Posted: Wed Jul 01, 2020 8:32 am
by rssreader
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.
Re: Why command "fetch" doesn't wait for output?
Posted: Wed Jul 01, 2020 8:26 pm
by sutrus
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 }
}
Re: Why command "fetch" doesn't wait for output?
Posted: Sun Mar 07, 2021 3:56 pm
by rssreader
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";
Re: Why command "fetch" doesn't wait for output?
Posted: Tue Mar 23, 2021 10:38 pm
by elico
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.
Re: Why command "fetch" doesn't wait for output?
Posted: Wed Mar 24, 2021 8:23 am
by Jotne
You do not need the ; after each line.
Its only needed when there are more than one command at the same line.
Re: Why command "fetch" doesn't wait for output?
Posted: Tue Dec 21, 2021 4:32 pm
by Chupakabra303
Mikrotik team, please add timeout option for Fetch tool!
Default timeout 10 (?) second is too small for specific tasks
failure: connection timeout
Re: Why command "fetch" doesn't wait for output?
Posted: Wed Dec 29, 2021 1:25 pm
by infabo
@rssreader have you found a solution? I have the same issue, where nothing after tool/fetch is executed in a script.
Re: Why command "fetch" doesn't wait for output?
Posted: Thu Jan 27, 2022 10:08 pm
by byosni
Eu também tenho o mesmo problema, @mikrotik coloque um "limit timeout" no tool fetch