To ensure that the PHP page runs in the background, write a monitoring script, assuming that the program exits unexpectedly, you can automatically restart.
Shell Script/usr/local/scripts/receve.sh content:
#!/bin/bash
#funtion: Keep receve.php running
php= "/usr/local/php5/bin/php"
program=
"receve.php" #start Dameo
$PHP/home/httpd/$PROGRAM >>/usr/local/scripts/phpshell/receve.out &
chpid= "$!";
echo "$chpid" >/usr/local/scripts/phpshell/receve.sid
echo "Child pid Yes $chpid"
echo "status is $?
While [1]
does wait $chpid
exitstatus= "$?"
echo "Child pid= $chpid is gone, $exitstatus" >>/usr/local/scripts/phpshell/receve.php_error.log
echo "date ' >>/usr/local/scripts/phpshell/receve.php_error.log
echo ' ************************** ' >>/usr/ Local/scripts/phpshell/receve.php_error.log sleep
$PHP/home/httpd/$PROGRAM >>/usr/local/ Scripts/phpshell/receve.out &
chpid= "$!";
echo "$chpid" >/usr/local/scripts/phpshell/receve.sid
echo "next child pid Yes $chpid"
echo "Next status is $ ?"
Done
Need to ensure that the monitor script runs normally, automatically restarts the script/usr/local/scripts/restart_r.sh every morning, writes to Crontab:
#!/bin/bash
echo "" >/tmp/receve_pid.txt
/bin/ps Ax | /bin/grep "Receve.sh" | /bin/grep-v "grep" | /bin/awk ' {print $} ' >/tmp/receve_pid.txt
no1pid= ' cat/tmp/receve_pid.txt | sort-r ' no2pid= ' cat/usr/
Local/scripts/phpshell/receve.sid | Sort-r '
if [-Z $no 1pid];then
echo "receve.sh pid is null, receve.sh are not running."
else
/bin/kill-9 "$no 1pid"
echo "receve.sh killed"
fi sleep
3
If [-Z $no 2pid];then
Echo receve.php pid is null and receve.php is not running.
else
/bin/kill-9 "$no 2pid"
echo "receve.php killed"
fi
rm-rf/usr/local/scripts/phpshell/ Receve.sid Sleep
3
/usr/local/scripts/receve.sh >/dev/null &
Crontab
Copy Code code as follows:
#restart receve.sh
* * * */usr/local/scripts/restart_r.sh
Note: script naming should avoid duplication and avoid killing your own process.