使用webman的自定义进程消费redis的订阅导致进程64000

会飞的鱼

问题描述

这里详细描述问题

程序代码

这里粘代码

<?php

namespace process;

use support\Log;
use support\Redis;

class Async
{
/**

  • 监听redis订阅
    */
    public function onWorkerStart()
    {
    Redis::subscribe('asyncpub',function ($data){
    if(!empty($data)){
    $data = json_decode($data, true);
    switch ($data['datatype']){
    case 'request':
    $this->https_curl($data['url'], [], 'GET');
    break;
    case 'cmd':
    exec($data['commend']['cli'].' '.implode(' ',$data['commend']['param']));
    break;
    default:
    }
    Log::info("订阅消息接收参数",['data'=>$data]);
    }
    });
    }

报错信息

这里粘贴报错

worker[async:122068] exit with status 64000
RedisException: read error on connection to 127.0.0.1:6379 in webman/vendor/illuminate/redis/Connections/PhpRedisConnection.php:461
Stack trace:
webman/vendor/illuminate/redis/Connections/PhpRedisConnection.php(461): Redis->subscribe()

操作系统及workerman/webman等框架组件具体版本

这里写具体的系统环境相关信息
4.2.1版本

194 1 0
1个回答

阿沁

有没有可能 127.0.0.1:6379 本地环境redis没有启动

  • 会飞的鱼 8天前

    肯定是启动了啊,但是由于是阻塞运行导致长时间的连接超时了,后面换成new 对象来调用就正常了 ~

  • tanhongbin 8天前

    new 对象和 使用静态有啥区别嘛? 是不是没有设置 一直阻塞 导致的 阻塞也是有超时默认时间的

  • 会飞的鱼 8天前

    不太清楚,用Redis::subscribe调用订阅 就一直繁忙 然后框架抛出异常64000,我是换成
    public function onWorkerStart()
    {
    $redis = new \Workerman\Redis\Client('redis://127.0.0.1:6379');
    $redis->subscribe('asyncpub',function ($channel, $message){
    if(!empty($message)){
    $message = json_decode($message, true);
    switch ($message['datatype']){
    case 'request':
    $this->https_curl($message['url'], [], 'GET');
    break;
    case 'cmd':
    shell_exec($message['commend']['cli'].' '.implode(' ',$message['commend']['param']));
    break;
    default:
    }
    }
    Log::info("订阅消息接收参数",['message'=>$message]);
    });
    }
    这种写法

×
🔝