Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$server->setting is NULL in onWorkerStart and onTask callback #5651

Closed
nguyenhothanhtam0709 opened this issue Jan 2, 2025 · 1 comment
Closed

Comments

@nguyenhothanhtam0709
Copy link

Issue:
I ran a simple http server script using swoole 6 and SWOOLE_THREAD mode, the var_dump($server->setting) of onTask and onWorkerStart callback show NULL, but in SWOOLE_PROCESS mode they show an setting array. Is this an expected behaviour or not?

1. What did you do? If possible, provide a simple script for reproducing the error.

I ran this script with Swoole 6

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use Swoole\Constant;
use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Http\Server;

$server = new Server('0.0.0.0', 3001, SWOOLE_THREAD);
$server->set([
    'hook_flags' => SWOOLE_HOOK_ALL,
    'enable_coroutine' => true,
    'task_enable_coroutine' => false,
    'debug_mode' => true,
    'display_errors' => true,
    'enable_preemptive_scheduler' => true,
    'worker_num' => 4,
    'reactor_num' => 2,
    'task_worker_num' => 2
]);

$server->on(Constant::EVENT_WORKER_START, function (Server $server) {
    var_dump($server->setting);
    $pid = getmypid();
    printf("Worker start on $pid\n");
});

$server->on('Task', function (Server $server, $task) {
    var_dump($server->setting);
});

$server->on('request', function (Request $request, Response $response) use ($server) {
    $server->taskWaitMulti([
        "AA"
    ]);
    $response->end("OK");
});

$pid = getmypid();
printf("[thread] Server started at http://0.0.0.0:$server->port on process {$pid}\n");
$server->start();

2. What did you expect to see?

the var_dump($server->setting) of onTask and onWorkerStart callback show array of value.

3. What did you see instead?

the var_dump($server->setting) of onTask and onWorkerStart callback show NULL.

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

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 6.0.0
Built => Dec 25 2024 10:41:50
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
thread => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 3.0.2 15 Mar 2022
dtls => enabled
http2 => enabled
json => enabled
pcre => enabled
zlib => 1.2.11
brotli => E16777225/D16777225
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled

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

5. What is your machine environment used (show your uname -a & php -v & gcc -v) ?

uname -a

Linux PF4GRXXV 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov  6 17:42:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

php -v

PHP 8.4.2 (cli) (built: Dec 25 2024 09:55:31) (ZTS)
Copyright (c) The PHP Group
Zend Engine v4.4.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.2, Copyright (c), by Zend Technologies

gcc -v

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.4.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04)
@nguyenhothanhtam0709 nguyenhothanhtam0709 changed the title $server->setting is NULL in onWorkerStart callback $server->setting is NULL in onWorkerStart and onTask callback Jan 2, 2025
@nguyenhothanhtam0709
Copy link
Author

it seems like $server-setting of workers and task workers are NULL when using SWOOLE_THREAD mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants