Thinkphp-queue中exceeded the timeout of 60 seconds的问题

文章介绍了在Thinkphp-queue中遇到的超时问题和运行队列时报错count():ParametermustbeanarrayoranobjectthatimplementsCountable的解决方法。针对超时问题,可以通过修改Listen.php文件中的timeout选项来增加超时时间。对于计数错误,建议更新Windows.php文件中的相关代码段,确保在调用count()函数时传入的是数组或可计数对象。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Thinkphp-queue中exceeded the timeout of 60 seconds 的问题 以及运行队列报错count(): Parameter must be an array or an object that implements Countable的解决方法

Thinkphp-queue中exceeded the timeout of 60 seconds 的问题
修改代码 vendor/topthink/think-queue/src/queue/command/Listen.php line 25~35

 public function configure()
    {
        $this->setName('queue:listen')
            ->addOption('queue', null, Option::VALUE_OPTIONAL, 'The queue to listen on', null)
            ->addOption('delay', null, Option::VALUE_OPTIONAL, 'Amount of time to delay failed jobs', 0)
            ->addOption('memory', null, Option::VALUE_OPTIONAL, 'The memory limit in megabytes', 256)   //修改占用内存大小
            ->addOption('timeout', null, Option::VALUE_OPTIONAL, 'Seconds a job may run before timing out', 1200)  //修改超时时间
            ->addOption('sleep', null, Option::VALUE_OPTIONAL, 'Seconds to wait before checking queue for jobs', 3)
            ->addOption('tries', null, Option::VALUE_OPTIONAL, 'Number of times to attempt a job before logging it failed', 0)
            ->setDescription('Listen to a given queue');
    }

运行队列报错count(): Parameter must be an array or an object that implements Countable的解决方法
thinkphp/library/think/process/pipes/Windows.php 修改代码 line 199~221

if (null !== $w && 0 < is_array($r)?count($r):0) {
            $data = '';
            while ($dataread = fread($r['input'], self::CHUNK_SIZE)) {
                $data .= $dataread;
            }

            $this->inputBuffer .= $data;

            if (false === $data || (true === $close && feof($r['input']) && '' === $data)) {
                $this->input = null;
            }
        }

        if (null !== $w && 0 < is_array($w) ? count($w):0) {
            while (strlen($this->inputBuffer)) {
                $written = fwrite($w[0], $this->inputBuffer, 2 << 18);
                if ($written > 0) {
                    $this->inputBuffer = (string) substr($this->inputBuffer, $written);
                } else {
                    break;
                }
            }
        }
### ThinkPHP 框架中的队列工作 #### 配置与初始化 在ThinkPHP框架中,为了使消息队列正常运作,需先完成必要的配置。对于基于Redis的消息队列,在`config/queue.php`文件内指定连接参数以及驱动名称为`redis`[^3]。 ```php return [ 'default' => env('QUEUE_DRIVER', 'sync'), 'connections' => [ 'sync' => [ 'type' => 'sync' ], 'beanstalkd' => [ 'type' => 'beanstalkd', 'host' => '127.0.0.1', 'port' => 11300, 'timeout' => 30, 'retry_time' => 3, 'tube' => 'think_default', ], 'swoole_table' => [ 'type' => 'table', 'host' => '', 'port' => '', 'table' => null, // swoole\Table 实例对象或者ID 'size' => 8192 * 16, 'key_size' => 128, 'data_size' => 1024, ], 'rabbitmq' => [ 'type' => 'rabbitmq', 'host' => 'localhost', 'port' => 5672, 'user' => 'guest', 'password' => 'guest', 'vhost' => '/', 'exchange_name' => 'think_queue_exchange', 'queue_name' => 'think_queue', 'routing_key' => '*', 'is_lazy' => false, 'ssl_options' => array( 'cafile' => '', 'local_cert' => '', 'local_key' => '', 'verify_peer' => true, ), ], 'redis' => [ 'type' => 'redis', 'host' => '127.0.0.1', 'port' => 6379, 'select' => 0, 'password' => null, 'persistent' => false, 'pool' => false, 'channel' => 'think', ] ], ]; ``` #### 启动与管理命令 当一切准备就绪之后,可以通过CLI工具启动监听器并处理任务: - `php think queue:listen`:持续运行监听来自不同通道的任务请求。 - `php think queue:work` :执行一次性的任务消费操作。 - 若要重启所有正在运行的工作进程,则应输入如下指令 `$ php think queue:restart$ php think queue:work` [^1]。 #### 常见问题解答 有时可能会遇到某些特定情况下的挑战,比如性能瓶颈或是错误调试困难等问题;针对这些问题有几种常规建议可供参考: - **优化性能**:如果发现系统响应速度变慢,考虑增加更多的消费者实例来分担负载压力,或者是调整数据库查询逻辑减少不必要的资源消耗。 - **排查故障**:面对程序抛出异常却难以定位原因的情况时,可以尝试开启详细的日志记录功能以便于后续分析具体位置发生的问题所在之处。 - **确保依赖项已安装**:确认已经通过Composer正确加载了所需的扩展包版本,并且服务器环境满足最低要求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值