编程技术记录 Good Luck To You!

mixphp 笔记

不写笔记,学会的东西就会忘记


mixphp v-2.1

启动api 

php bin/mix.php api:start


启动命令行的协程迟redis队列 

进入项目根目录 启动这cli命令:   php bin/mix.php cpd  

订单的方法在 app/Console/Commands/CoroutinePoolDaemonCommand 

这个类的 main方法里面 redis队列名字我改成了 all

 在一般的订阅写上下面的方法,用type来区别类型,

             $redisPool = context()->get('redisPool');
            $redis = $redisPool->getConnection(); //连接redis
            $jsonArraySms['type'] = 'sms'//根据这个类型来做队列的分发
            $jsonArraySms['mobile'] = $mobile;
            $jsonArraySms['code'] = $code;
            $jsonSrtSms = json_encode($jsonArraySms); //压缩数组为字符串,push进去all队列
            $redis->rPush('all'$jsonSrtSms); //  插入队列名为all 的最后面类型为 sms



在这个类里面 消费
App\Console\Workers\CoroutinePoolDaemonWorker
     /**
     * 处理
     * @param $data
     */
    public function handle($data)
    {
        // TODO: Implement handle() method.
        var_dump($data);
        var_dump(json_decode($data));
        //判断 json解压
        /*
        object(stdClass) {
        ["type"]=>
        string(3) "sms"
        ["mobile"]=>
        string(11) "1821***7335"
        ["code"]=>
        string(6) "1234"
        }
         */

        //是否 空对象并且值是否有一个是空。都不是空就
        if (!empty($data)) {
            $data = json_decode($data);
            $type = $data->type;
            switch ($type) {
                case 'sms':
                    unset($data->type);
                    $this->typeSms($data);
                    break;
                case 'email':
                    unset($data->type);
                    $this->typeEmail($data);
                    break;
                default:
                    var_dump($data);
                    break;
            }

        }

    }



2:mixphp 热更新 

大佬写了一个牛鼻的东西 叫swoolefor github地址在

https://github.com/mix-php/swoolefor

下载里面 swoolefor.phar单文件 放到服务器项目的根目录。

image.png

image.png


2.1热更新 运行命令 和详解

php swoolefor.phar --exec="/www/server/php/73/bin/php /www/wwwroot/mix.gzwmdy.cn/mix/bin/mix.php cpd arg..."    这个的bin/mix.php cpd 等于 启动这cli命令:   php bin/mix.php cpd  

php swoolefor.phar --exec="/www/server/php/73/bin/php /www/wwwroot/mix.gzwmdy.cn/mix/bin/mix.php api:start arg..."  这个的bin/mix.php api:start  普通的启动命令php bin/mix.php api:start




作者:admin 分类:未分类 浏览:820 评论:0