# 创建test.php
<?php

while(1){
sleep(1);
    if(!isset($flag)){
        $flag = 1;
    }

$flag = $flag + 1;
file_put_contents('a.txt' ,$flag . ',', FILE_APPEND);
}

#后台执行  在执行命令后面加&   也可用nohup 
php test.php &

#杀死进程
pkill -9 test.php

#守护进程 listen.sh

#!/bin/bash
alive=`ps aux|grep test.php|grep -v grep|wc -l`
if [ $alive -eq 0 ]
then
php /root/test/test.php > /dev/null &
fi

#设置定时监听
crontab -e

* * * * * sh /root/test/listen.sh


0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用*标注