w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Is it possible to terminate a code part when it's execution time is getting longer than a specified time limit?

You can just break the loop if it exceeds the time:

$max = 1000; //maximum time in milliseconds
$start = microtime(true);
foreach($tasks as $t) {
    // Execute the task
    $t->execute();
    if (microtime(true) - $start > $max) {
        break;
    }
}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.