Hafiz Atta Ur Rahman Hafiz Atta Ur Rahman - 2 months ago 26
PHP Question

PHP Sleep function With While Loop

I am using Ubuntu Server 14.04 I have some issue in my script ...script give me response very well if i use die instead of sleep after echo in else condition but when i use sleep(3600) after echo in else condition it is not giving me any response ...this is my code

date_default_timezone_set("Europe/London");

$st_time = '12:00';

$et_time = '18:00';

$cur_time = date("H:i");

while (1) {

if (($cur_time < $et_time) && ($cur_time > $st_time)) {
//Enter and perform Some function
} else {
echo 'sleep for one hour Bye';
sleep(3600)
}
}

Answer

Try this code, sleep code in micro seceonds:

date_default_timezone_set("Europe/London");
$st_time = '12:00';
$et_time = '18:00';
$cur_time = date("H:i");
while (true) {
if (($cur_time < $et_time) && ($cur_time > $st_time)) {
//Enter and perform Some function
} else {
usleep(3600);
echo 'sleep for one hour Bye';        
 }
}