1

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)
    }
}
Rasclatt
  • 12,498
  • 3
  • 25
  • 33
  • 1
    What are you *expecting* to happen? `sleep(3600)` means to wait for 60 minutes; that means it'll be an hour before you get a response. However, PHP is often configured to abort scripts that take more than a short time (30 seconds or so), so you might just get an error when that happens. – Wyzard Dec 11 '14 at 05:50
  • you can check this post, maybe helpful http://stackoverflow.com/questions/740954/does-sleep-time-count-for-execution-time-limit and http://stackoverflow.com/questions/8518203/max-execution-time-and-sleep – tzafar Dec 11 '14 at 05:52

1 Answers1

2

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';        
 }
}
Ikhlak S.
  • 8,578
  • 10
  • 57
  • 77
Sharma Vikram
  • 2,440
  • 6
  • 23
  • 46
  • usleep here being 3600, means 0.0036 seconds. this script going to increase cpu load a lot. you need to use sleep() instead. or use usleep(3600000000) – Armin Nikdel Aug 07 '20 at 03:01