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

The go function does not working on a controller #467

Closed m3m0r7 closed 3 years ago

m3m0r7 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)
swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.6.1
Built => Feb  7 2021 00:55:40
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1d  10 Sep 2019
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.11
mutex_timedlock => enabled
pthread_barrier => enabled
futex => 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 => 8388608 => 8388608
swoole.use_shortname => On => On

I'm using swoole on Docker. Here is my Dockerfile

FROM php:7.4.14-zts

RUN apt -y update && \
     apt-get install -y \
     libicu-dev \
     libonig-dev \
     libzip-dev \
     libmagick++-dev \
     libmagickwand-dev \
     libpq-dev \
     libmemcached-dev \
     libfreetype6-dev \
     libjpeg62-turbo-dev \
     libpng-dev \
     libwebp-dev \
     libxpm-dev \
     git \
     npm \
     default-jre \
     libxml2-dev \
     libcurl4-openssl-dev \
     libssl-dev

RUN docker-php-ext-install -j$(nproc) pdo_mysql
RUN docker-php-ext-install -j$(nproc) intl
RUN docker-php-ext-install -j$(nproc) zip
RUN docker-php-ext-install -j$(nproc) sockets

RUN pecl install igbinary && docker-php-ext-enable igbinary
RUN pecl install parallel && docker-php-ext-enable parallel

# Install redis manually because we need enable to igbinary
RUN pecl install --onlyreqdeps --nobuild redis && \
    cd "$(pecl config-get temp_dir)/redis" && \
    phpize && \
    ./configure --enable-redis-igbinary && \
    make && make install && \
    docker-php-ext-enable redis

RUN git clone https://github.com/swoole/swoole-src.git &&  \
    cd swoole-src && \
    git checkout v4.6.1 && \
    phpize && \
    ./configure --enable-sockets --enable-http2 --enable-openssl --enable-swoole-curl --enable-swoole-json && \
    make -j$(nproc) && \
    make install && \
    docker-php-ext-enable swoole

RUN pecl install memcached && docker-php-ext-enable memcached
RUN pecl install imagick && docker-php-ext-enable imagick
RUN pecl install xdebug

RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd
RUN docker-php-ext-install -j$(nproc) soap

// ... omitted
  1. Please provide your Laravel/Lumen version.
  1. Which release version of this package are you using?
  1. What did you do? If possible, provide a recipe for reproducing the error.

I tried to use the go function on a controller but it is not working.

Here is my code:

    public function index(Request $request)
    {
        \Swoole\Runtime::enableCoroutine();
        $wg = new \Swoole\Coroutine\WaitGroup();
        go(function () use ($wg) {
            var_dump(1);
            $wg->add();
            \Co::sleep(3);
            $wg->done();
            var_dump(2);
        });

        go(function () use ($wg) {
            var_dump(1);
            $wg->add();
            \Co::sleep(3);
            $wg->done();

            var_dump(2);
        });

        $wg->wait();
    }

it will show var_dump messages on the console but swoole will be crashed.

int(1)
int(1)
int(2)
[2021-02-07 12:42:53 $56.0] WARNING check_worker_exit_status: worker#12[pid=85] abnormal exit, status=0, signal=11
A bug occurred in Swoole-v4.6.1, please report it.
The Swoole developers probably don't know about it,
and unless you report it, chances are it won't be fixed.
You can read How to report a bug doc before submitting any bug reports:
>> https://github.com/swoole/swoole-src/blob/master/.github/ISSUE.md 
Please do not send bug reports in the mailing list or personal letters.
The issue page is also suitable to submit feature requests.

And I tried to use barrier class but it is not working.

    public function index(Request $request)
    {
        \Swoole\Runtime::enableCoroutine();
        $barrier = \Swoole\Coroutine\Barrier::make();

        go(function () use ($barrier) {
            var_dump(1);
            \Co::sleep(3);
            var_dump(2);
        });

        go(function () use ($barrier) {
            var_dump(1);
            \Co::sleep(3);
            var_dump(2);
        });

        \Swoole\Coroutine\Barrier::wait($barrier);
    }

it will show var_dump messages completely on the console but swoole will be crashed.

int(1)
int(1)
int(2)
int(2)

it will show the same message.

[2021-02-07 12:48:50 $54.0] WARNING check_worker_exit_status: worker#11[pid=82] abnormal exit, status=0, signal=11
A bug occurred in Swoole-v4.6.1, please report it.
The Swoole developers probably don't know about it,
and unless you report it, chances are it won't be fixed.
You can read How to report a bug doc before submitting any bug reports:
>> https://github.com/swoole/swoole-src/blob/master/.github/ISSUE.md 
Please do not send bug reports in the mailing list or personal letters.
The issue page is also suitable to submit feature requests.
  1. What did you expect to see?

I wanna use the go function on controllers, models, and so on.

  1. What did you see instead? No
m3m0r7 commented 3 years ago

The problem reason is installing the newrelic module on PHP. I remove newrelic installation from the Dockerfile and I resolved it.