ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
## 独立部署 独立部署即为在后端运行程序,让程序跑在后台。 ## daemon 参数 - 通过骨架代码中自带的 `-d/--daemon` 参数使程序在后台执行。 ~~~ $ php bin/mix.php web -d ~~~ ~~~ $ php bin/mix.php web --daemon ~~~ ## nohup 通过 Linux 的 `nohup` 命令使程序在后台执行。 ~~~ $ nohup php bin/mix.php web >/dev/null 2>&1 & ~~~ ## shell 通常我们会使用一个简单的 shell 脚本来管理 mix 进程,保存以下脚本为 `mix.sh`: - `php` 使用的 php 绝对路径 - `file` mix 入口文件绝对路径 - `cmd` 使用的 mix 命令名称 - `numprocs` 开启的进程数量,大于 1 就会执行端口复用多开 ~~~ #!/bin/sh echo "============`date +%F' '%T`===========" php=/usr/local/php/bin/php file=/data/mix/bin/mix.php cmd=web numprocs=1 getpid() { docmd=`ps aux | grep ${file} | grep ${cmd} | grep -v 'grep' | grep -v '\.sh' | awk '{print $2}' | xargs` echo $docmd } start() { pidstr=`getpid` if [ -n "$pidstr" ];then echo "running with pids $pidstr" else if [ $numprocs -eq 1 ];then $php $file $cmd -d else i=0 while(( $i<$numprocs )) do $php $file $cmd -r -d let "i++" done fi sleep 1 pidstr=`getpid` echo "start with pids $pidstr" fi } stop() { pidstr=`getpid` if [ ! -n "$pidstr" ];then echo "Not Executed!" return fi echo "kill $pidstr" kill $pidstr } restart() { stop sleep 1 start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; esac ~~~ 脚本如何使用: - `sh mix.sh start` - `sh mix.sh stop` - `sh mix.sh restart` > 有些公司喜欢使用 crontab 拉起异常停止的程序,可以定时调用该脚本的 start 方法