swooletw / laravel-swoole

High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.
MIT License
4.04k stars 390 forks source link

Websocket emit doesn't work in Jobs #482

Open gitlky opened 3 years ago

gitlky commented 3 years ago

Make sure you read Issues Guideline and answer these questions before submitting your issue. Thanks! (Any non-English issues will be closed immediately.)

  1. Please provide your PHP and Swoole version. (php -v and php --ri swoole)
    PHP 7.4.16 (cli) (built: Mar  6 2021 04:24:10) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
    
    swoole

Swoole => enabled Author => Swoole Team team@swoole.com Version => 4.6.5 Built => Apr 14 2021 20:52:21 coroutine => enabled with boost asm context epoll => enabled eventfd => enabled signalfd => enabled spinlock => enabled rwlock => enabled zlib => 1.2.11 brotli => E16777225/D16777225 mutex_timedlock => enabled pthread_barrier => enabled futex => enabled async_redis => enabled

Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => On => On swoole.unixsock_buffer_size => 8388608 => 8388608


2. Please provide your Laravel/Lumen version.

Laravel Framework 8.37.0

3. Which release version of this package are you using?

^2.8

4. What did you do? If possible, provide a recipe for reproducing the error.

<?php

namespace App\Jobs;

use Log; use Illuminate\Bus\Queueable; use Illuminate\Console\Command; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Log; use SwooleTW\Http\Websocket\Facades\Websocket;

class GenBarcodeJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public function __construct()
{
   Log::info('coming');
}

public function handle()
{

    Websocket::broadcast()->emit('starting',[]);
}

}


5. What did you expect to see?

I hope the websokct:emit ()  work in jobs

6. What did you see instead?

it  can't work
Arkanius commented 3 years ago

Are you using socket.io?

gitlky commented 3 years ago

@Arkanius i'm using websockt

gitlky commented 3 years ago

I wanna notify all online websocket user do something after the queue job finish; I'm sure the queue job is worked,because the log is printed, and client was Connected; but the all websocket client dose't received message from server

In a nutshell:
Websocket::broadcast()->emit('starting',[]); work in Controller, inoperation in Queue Job GenBarcodeJob::dispatch();

ZYY-XU commented 2 years ago

我想在队列作业完成后通知所有在线 websocket 用户做一些事情; 我确定队列作业有效,因为打印了日志,并且客户端已连接; 但是所有 websocket 客户端都没有收到来自服务器的消息

简而言之: Websocket::broadcast()->emit('starting',[]); 在Controller中 工作,在Queue Job中不操作 GenBarcodeJob::dispatch();

Friend, has your problem been solved?