Skip to content

子进程中调用server->push函数卡住,没有错误 #2977

@linkdrone

Description

@linkdrone

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a simple script for reproducing the error.
<?php
$server = new Swoole\WebSocket\Server("127.0.0.1", 9502);

$server->on('open', function($server, $req) {
    echo "connection open: {$req->fd}\n";
});

$server->on('message', function($server, $frame) {
    echo "received message: {$frame->data}\n";
    $server->push($frame->fd, json_encode(["hello", "world"]));
});

$server->on('close', function($server, $fd) {
    echo "connection close: {$fd}\n";
});


//启动子进程
$producer = new \swoole_process(function (\swoole_process $worker) {
    //swoole_event_add()
    global $server;
    while(true)
    {
//                usleep(500);
//                Service::$server->push(1, '000');
//                $data = $worker->read();
//                var_dump(microtime(true));
        sleep(1);
        var_dump('111');
        var_dump($server->push(1, 'xxx')); //注:此处卡住,没有错误信息输出
        var_dump('222');
    }
}, false, SOCK_DGRAM);
$producer->start();

$server->start();

swoole_process::wait();
  1. What did you expect to see?

希望可以知道卡住的原因或者报错信息

  1. What did you see instead?
    如果是报错了希望得知错误原因,如果是卡住了,这是什么原因导致的?有木有相关文档?

  2. What version of Swoole are you using (show your php --ri swoole)?

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.4.12
Built => Nov 25 2019 14:29:03
coroutine => enabled
kqueue => enabled
rwlock => enabled
http2 => enabled
pcre => enabled
zlib => 1.2.11
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.display_errors => On => On
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.unixsock_buffer_size => 262144 => 262144
swoole.use_shortname => On => On
  1. What is your machine environment used (including version of kernel & php & gcc) ?

macos

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions