Community discussions

MikroTik App
 
rssreader
just joined
Topic Author
Posts: 5
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: 1353
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: 5
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
Frequent Visitor
Frequent Visitor
Posts: 55
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: 5
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
newbie
Posts: 37
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 }
}

Who is online

Users browsing this forum: manojdhanda and 15 guests