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.
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.
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
Try to put a delay of 5 seconds before and 10 seconds after fetch command
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.
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 }
}
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";
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.
You do not need the ; after each line.
Its only needed when there are more than one command at the same line.
Mikrotik team, please add timeout option for Fetch tool!
Default timeout 10 (?) second is too small for specific tasks
failure: connection timeout
@rssreader have you found a solution? I have the same issue, where nothing after tool/fetch is executed in a script.
Eu também tenho o mesmo problema, @mikrotik coloque um “limit timeout” no tool fetch