Reputation: 6233
I have a cronjob which imports a huge file and then processes it. The import process takes a lot of time however after 600 seconds the server I am running the script on aborts the cronjob (timeout). After talking to a server technician he told me I needed to output something during the process of importing in order for the script to not abort after 10 minutes.
My question now is: let's say we have a function import()
which imports the file (this function takes approximately 20 minutes to run). Is there any way to simultaneously echo
an output every for example 5 minutes? Or is this not possible due to the fact that PHP code is always processed in sequence?
Upvotes: 1
Views: 104
Reputation: 669
If it is an iterative process you could set a variable $last_echo
with the value of time()
.
Then on each iteration check if time() - $last_echo > 300
.
Example:
$last_echo = time();
while (true) {
//Do process
if (time() - $last_echo > 300) {
echo '.';
}
}
Upvotes: 1