PHP获取CentOS服务状态,在Centos7.x上如何以后台服务方式运行PHP文件

(1)如果你要执行的php文件是定时执行的,通过Linux crontab定时执行任务,基本格式为

*  command

分 时 日 月 周 命令

(2)如果你是不断要在后台跑脚本,也可以借助一些进程控制工具,譬如Supervisor,举个之前在ubuntu配置的例子:

//如果没有安装supervisor,要先安装,已经安装的跳过这一步

$ sudo apt-get install supervisor

$ cd /etc/supervisor/conf.d

//创建一个进程配置文件

$ sudo vi laravel_queue_order.conf

//内容如下:

[program:yourProgramName]

process_name=%(program_name)s_%(process_num)02d

command=php yourCommand

directory=/var/www/yourproject

autostart=true

autorestart=true

numprocs=4

stdout_logfile=/var/www/yourproject/storage/logs/yourProjectLogName.log

//进程数numprocs由自己确定

//开启进程

sudo service supervisor start

sudo supervisorctl update

sudo supervisorctl reread

sudo supervisorctl start yourProgramName

//可以使用htop查看进程是否正确运行中

$ htop

//如果有出现command为php yourCommand的进程,代表进程启动成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值