无限期运行 PHP (CLI) 脚本 [英] Run a PHP (CLI) script indefinitely
本文介绍了无限期运行 PHP (CLI) 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个无限期运行的 PHP 脚本,但我似乎找不到一个好的方法来做到这一点.我的服务器在 Windows Server 2008 上运行.
I need to have a PHP script running indefinitely, but I can't seem to find a good way to do this. My server runs on Windows Server 2008.
你认为我可以依赖 Timer Tasks 吗?有更好的选择吗?
Do you think I can rely on Timer Tasks? Is there a better alternative?
提前致谢.
推荐答案
如果您需要脚本持续运行,而不是定期启动以完成它所做的任何工作,那么您需要它进入无限循环,因此:
If you need the script to run constantly, rather than being started periodically to do whatever job it does, then you need it to enter an endless loop, thus:
while (1) {
do_something();
sleep(1);
};
不要省略 sleep()
语句,除非您不介意脚本占用整个处理器.
Do not omit the sleep()
statement, unless you don't mind the script eating your entire processor.
这篇关于无限期运行 PHP (CLI) 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文