-1

I need a method to notify my application that one minute has elapsed in php. This method is of type void

I try it:

public function minutes() : void {

    ini_set('max_execution_time', 60);

    $i = 0;

    while ( $i < 60 ){
        $i++;
        sleep(1);
    }
TarangP
  • 2,711
  • 5
  • 20
  • 41
Leandro Matilla
  • 911
  • 4
  • 14

2 Answers2

0

Here are two ways. One with a while loop and the other uses sleep(); Sleep() is the better way to go.

function minutes(){

$time1 = time();

do{

$time2 = time();

}while($time2 - $time1 < 60);

echo '1 minute has passed.';


}

function minutes1(){

sleep(60);

echo '1 minute has passed.';

}

minutes(); //<--Uses while loop.
minutes1(); //<--Uses sleep().  This is the better way.
Joseph_J
  • 3,654
  • 2
  • 13
  • 22
0

Try this

set_time_limit(0);
ob_implicit_flush();

public function minutes() : void {

 $i = 0;

 while ( $i < 5 /*change here whatever you want */ ){
        sleep(60);
        $i++;
        echo "$i minute(s) has passed.";
 }
}
  • Won't setting the max execution time kill the script at 60 secs? OP won't be able to do anything after that. – Joseph_J Apr 10 '18 at 06:15