保持PHP脚本作为守护程序运行的最佳方法是什么? [英] What's the best way to keep a PHP script running as a daemon?

查看:57
本文介绍了保持PHP脚本作为守护程序运行的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使PHP脚本作为守护程序运行的最佳方法是什么,以及检查是否需要重新启动的最佳方法是什么.

What is the best way to keep a PHP script running as a daemon, and what's the best way to check if needs restarting.

我有一些脚本需要运行24/7,大多数情况下,我可以使用 nohup来运行它们.但是,如果它们掉线了,监视它以便使其能够自动重新启动的最佳方法是什么?

I have some scripts that need to run 24/7 and for the most part I can run them using nohup. But if they go down, what's the best way to monitor it so it can be automatically restarted?

推荐答案

如果您不能使用(正确的)init结构来执行此操作(您正在共享主机上,等等),请使用cron运行脚本(可以用您喜欢的任何一种语言编写)每隔几分钟检查一次它们是否正在运行,并在必要时重新启动它们.

If you can't use the (proper) init structure to do this (you're on shared hosting, etc.), use cron to run a script (it can be written in whatever language you like) every few minutes that checks to see if they're running, and restarts them if necessary.

这篇关于保持PHP脚本作为守护程序运行的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆