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!

2

2 Answers 2

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>';
}
?>
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Task Scheduler is at least as useful as Cron

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.