我需要从Windows WAMP服务器运行脚本。它应该是这样工作的:
<?php
while(1){
echo 'Start<br>';
//Some magic here to wait 5 seconds
echo 'End<br>';
}
?>
我想要的是自动工作:打印出Start
->等待5秒->打印出End
->打印出Start
->等待5秒-> ....
在php中,Sleep(5);
不是一个选项,因为(据我所知)它将等待程序结束,之后它将输出Start
和End
。我不能使用Windows Task Scheduler
,因为在未来,脚本将在linux服务器上运行。但是我不能用cron工作,因为我在windows上。所以,基本上我需要像cron这样的东西,但在windows和wamp的php localhost。
所以,我的问题是:是否有任何选项在php/javascript/无论如何迭代一个脚本'活'与暂停?
PYTHON示例:
import time
for i in range(10):
print('Start')
time.sleep(5)
print('End')
谢谢你的每一个建议!
我想你应该只使用windows任务调度程序,但如果你真的需要一个php
脚本,你可以使用这样的东西:
<?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提到的,你需要一个像样的任务计划,你也可以看看这篇文章来获得windows中的cron功能