3

I need run script from Windows WAMP server. It should work like this:

<?php
while(1){
    echo 'Start<br>';
    //Some magic here to wait 5 seconds
    echo 'End<br>';
}
?>

What I want is automatic work: print out Start -> wait 5 seconds -> print out End -> print out Start -> wait 5 seconds -> ....

In php, Sleep(5); is not an option because (as far as I can tell) it will wait for end of program and after that it will output Start and End. I cannot use Windows Task Scheduler, because in future, script will run at linux server. But I cannot work with cron because I am on windows. So, basically I need something like cron, but in php on windows and wamp localhost.

So, my question is: Is there any option in php/javascript/whatever how to iterate one script 'live' with pause?


PYTHON EXAMPLE:

import time
for i in range(10):
    print('Start')
    time.sleep(5)
    print('End')

Thank you for every advice!

Anchor_Chisel
  • 166
  • 1
  • 8
  • 1
    CRON is the linux equivilent of "Windows Task Scheduler". So while in windows, use Windows Task Scheduler, when move to linux, setup a CRON http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/ – Ron Dadon Oct 11 '15 at 10:14
  • it as answered here http://stackoverflow.com/questions/3445222/php-output-with-sleep – MrFreezer Oct 11 '15 at 10:24

2 Answers2

0

I gues you should just use windows task scheduler, but if you really need a php script, you can use something like:

<?php
set_time_limit(0); // no time limit to execute the script
ignore_user_abort(true); //ignore if the user closes the browser or shell session
while(1){
    echo 'Start<br>';
    sleep(5);
    echo 'End<br>';
}
?>
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
0

Like Pedro mentioned you need a decent task schedular, you can also have a look @ this article to get the cron kind of functionality in windows

usman zafar
  • 220
  • 2
  • 9