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)
    }
}
2
  • 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, 2014 at 5:50
  • you can check this post, maybe helpful stackoverflow.com/questions/740954/… and stackoverflow.com/questions/8518203/…
    – tzafar
    Dec 11, 2014 at 5:52

1 Answer 1

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';        
 }
}
1
  • 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) Aug 7, 2020 at 3:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.