I have 2 files running on loop, master.php and bot.php:
master.php
<?php
while (1) {
include 'bot.php';
sleep(60);
}
bot.php
<?php
declare(ticks=1);
define('START_TIME', time());
// lambda uses START_TIME constant
register_tick_function(function() {
if (time() - START_TIME > 9000) {
echo 'Script execution halted. Took more than 20 seconds';
exit(1);
}
}, true);
include_once 'onefile.php';
include 'somefile.php';
include 'somefile2.php';
?>
I need to ensure that bot.php doesn't take longer than x seconds. If it does I need to gracefully stop/break the bot.php loop but keep the master.php running the infinite loop.
I have tried Josh Trii Johnston's answer from this question but the problem is that it stops everything including master.php loop (which is the file I will initially run and I don't want to stop)
I need to create this timeout because bot.php performs some tasks on remote servers and sometimes (rarely) it time-outs and freezes forever. This timeout is just to ensure that in those cases the loop will break and a new cycle begin.