設定php指令碼為守護程序

2021-09-22 19:56:00 字數 574 閱讀 2412

建立test.php指令碼:

#!/usr/bin/php

<?php

while(true)

?>

守護程序命令:

php test.php > /dev/null &
/dev/nul是指指令碼輸出列印到空裝置,也就是不記錄,&為後台執行模式

建立服務退出重啟指令碼:

#!/bin/bash

alive=`ps aux|grep test.php|grep -v grep|wc -l`

if [ $alive -eq 0 ]

then

php test.php > /dev/null &

fi

設定crontab定時任務,每分鐘執行監測指令碼一次:

* * * * * test.sh > /dev/null &
nohup後台執行命令:

nohup php test.php > /dev/null &

設定守護程序

1.守護程序 守護執行緒在程式關閉時會突然停止 daemon true t threading.thread target do2,daemon true 或者 t threading.thread target do2 t.setdaemon true 2.join阻塞 如果為執行緒例項新增t.s...

php守護程序

class daemon 啟動程序 return bool public function main this logmessage running.this isrunning true while this isrunning return true 停止程序 return void publi...

PHP守護程序

php也是可以直接進行守護程序的啟動與終止的,相對於shell來說會簡單很多,理解更方便,當然了php的守護程序要實現自動重啟還是要依賴於shell的crontab日程表,每隔一段時間去執行一次指令碼看指令碼是否需要重啟,如果需要則殺掉程序刪除runfile檔案,重新啟動並在runfile檔案中寫入...