简体   繁体   English

我怎样才能 24/7 全天候运行 php 脚本?

[英]How can I run a php script 24/7?

I have a php script which generates random values for two different variables in a different interval.我有一个 php 脚本,它在不同的时间间隔内为两个不同的变量生成随机值。 I need to have this script run 24/7 and in the background (page must be closed).我需要让这个脚本 24/7 并且在后台运行(页面必须关闭)。 Any help would be appreciated.任何帮助,将不胜感激。 Thanks in advance.提前致谢。

I would suggest you to configure a cron job to resolve your problem.我建议您配置一个 cron 作业来解决您的问题。 Loop in php is not good enought for this, as practice shows, because if php loop script just end with error it will never start again without your help.正如实践所示,在 php 中循环对此还不够好,因为如果 php 循环脚本以错误结束,没有您的帮助,它将永远不会再次启动。

Write an infinite loop and run the PHP file on the server.编写一个无限循环并在服务器上运行 PHP 文件。

while(true){
  // generates random values for two different variables in a different interval
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM