如何让php程序像服务器中的服务一样运行?
问题描述:
嗨
我要写一个应该在我的服务器上一直运行的程序(24/7)就像服务一样......
每当我的服务器运行时,该程序应该正在运行,每当我启动/重新启动我的机器时,程序应该自动启动并运行。
该程序将是在PHP中。我怎么能让它像服务一样运行?
那怎么办呢?
hi
I''m going to write a program that should be running all the time (24/7) in my server say like a service..
Whenever my server is running this program should be running and whenever i start/restart my machine the program should automatically start and run.
The program will be in php. How can i make this to run like a service?
So how can do this ?
答
转到PHP论坛希望他们能够更好地指导你
Moving to PHP forum in hopes they will be able to guide you better
你是什么意思一直在运行?如果你有一个PHP脚本总是在做什么的话,这会咀嚼很多你的CPU。
听起来我希望PHP脚本可以重复运行,比如说每分钟或每5分钟或每10分钟,或每小时一次或类似的事情。那是你要的吗?如果是这样,您可以将PHP脚本配置为以独立方式运行(无需Web服务器或PHP-CLI模式),然后设置批处理程序以定期运行脚本。如果您正在使用Linux计算机,则可以通过设置cron作业来完成此操作。如果你使用Windows,不知道你做了什么。
What do you mean by "running all the time"? That is going to chew up a lot of your CPU if you have a PHP script always doing something.
It sounds to me like you wish a PHP script to run repeatedly, say for example every minute or every 5 minutes or every 10 minutes, or once each hour or something like that. Is that what you want? If so, you can configure your PHP script to run in a standalone fashion (without a web server, or the PHP-CLI mode) and then set up a batch program to run your script at the regular intervals you desire. If you are working on a Linux machine, you would do this by setting up a cron job. Not sure what you do if you are using Windows.
我将使用linux,我希望该程序像服务一样运行......
我很确定,这个程序应该一直运行,这个程序有非常重要的监控和排队的东西。所以它需要运行..
我想到了cron,但是例如如果crontab本身失败,谁将启动该程序。
实际上我希望程序在服务器运行时像服务一样运行......如果在服务器启动/重启时自动启动它会非常好。 />
希望找到解决方案
i''m going to use linux and i want that program to run all the like a service...
I''m sure about that, this program should be running all the time,this program has very important monitoring and queuing stuff. so it need to be running..
I thought of cron, but for example if the crontab itself fails, who will initiate that program.
Actually i want that program to be running like a service whenever the server is running... it can be very nice if is automatically started when the server is started/restarted.
Hoping for a solution