sleep 


php128 apg

DELAYS the program executions by a given number of  s, (seconds) .





This function returns a non-zero value if the call was interrupted by a signal.

On Windows™, this value is always 192, the WAIT_IO_COMPLETION constant within the Windows™ API.

On others environments the returned value will be the number of seconds to sleep.

This function will generate a E_WARNING, if the provided number of seconds is negative.



<?php

int sleep 
int $seconds )


where,

$seconds Number of seconds to delay the program execution
  
?>

 $seconds 


Number of seconds to delay the program execution.



  1 EXERCISE   

<?php

$lang 
'jp';

$str_tzg date_default_timezone_get();

$pt 'Fuso horário atual:<br>';
$en 'Current Time Zone:<br>';
$jp 'タイムゾーンセット:<br>';

echo 
'<br>' . $$lang  '&nbsp;' $str_tzg '<br><br>';

echo 
date("l F d Y H:i:s");
echo 
'<br><br>';

$time2sleep 15;
sleep($time2sleep);

echo 
date("l F d Y H:i:s");

?>

 RESULT   

 イムゾーンセット  
America/Sao_Paulo

Wednesday December 09 2020 17:09:48

Wednesday December 09 2020 17:10:03

This is only one of the possible results.
You must try other possibilities.

This exercise delays the execution time by 15 seconds


  2 EXERCISE   

<?php

$lang 
'en';

$str_tzg date_default_timezone_get();

$pt 'Fuso horário atual:<br>';
$en 'Current Time Zone:<br>';
$jp 'タイムゾーンセット:<br>';

echo 
'<br>' . $$lang  '&nbsp;' $str_tzg '<br><br>';

echo 
date("l F d Y H:i:s");
echo 
'<br><br>';

$time2sleep = -5
// Number of seconds less than zero

sleep($time2sleep);

echo 
date("l F d Y H:i:s");

?>

 RESULT   

 Current Time Zone  
 America/Sao_Paulo 

PHP 7.4.XX

Warning ...

PHP 8.0.XX

Fatal error ...

Because number of seconds for the sleep must be greater than or equal to 0.