sleep 


php apg

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



<?php

int sleep 
int $seconds )


where,

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

 $seconds 


Number of seconds to delay the program execution.





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 Warning: ... in PHP 7.4.XX or Fatal error: ... in PHP 8.0.XX, if the provided number of seconds is negative.



  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);

// Delays the execution time by 15 seconds

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

?>

  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
// This generates Warning in PHP 7.4.XX 
// and Fatal error in PHP 8.0.XX 

sleep($time2sleep);

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

?>