swoole / swoole-src

🚀 Coroutine-based concurrency library for PHP
https://www.swoole.com
Apache License 2.0
18.42k stars 3.16k forks source link

Can not change settings for other opened port #5431

Closed grencik closed 1 month ago

grencik commented 2 months ago

I have this simple example:

<?php

use Swoole\Server;

$server = new \Swoole\Http\Server("0.0.0.0", 7101);
$port2 = $server->addListener("0.0.0.0", 7102, SWOOLE_SOCK_TCP);

$server->set([
                 'enable_delay_receive' => false,
             ]);

$port2->set([
                'worker_num' => 2,
                'max_request' => 100,
                'enable_delay_receive' => true,
            ]);

$server->on('request', function ($request, $response) {
    var_dump($request);
});

$port2->on('connect', function (Server $server, $fd, $reactorId) {
    var_dump($server->setting);
});

$port2->on('receive', function (Server $server, $fd, $reactorId, $data) {
    var_dump($data);
});

$server->start();

When I connect to TCP port 7102 with telnet, I get this settings:

array(9) {
  ["enable_delay_receive"]=> bool(false)
  ["worker_num"]=> int(1)
  ["task_worker_num"]=> int(0)
  ["output_buffer_size"]=> int(4294967295)
  ["max_connection"]=> int(100000)
  ["open_http_protocol"]=> bool(true)
  ["open_mqtt_protocol"]=> bool(false)
  ["open_eof_check"]=> bool(false)
  ["open_length_check"]=> bool(false)
}

I am interested in enable_delay_receive attribute, but also other settings are overriden. It should have different settings.

My environment:

Swoole (compiled from git in docker container)

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 5.1.3
Built => Jul 24 2024 11:33:02
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 3.0.13 30 Jan 2024
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
zlib => 1.2.13
brotli => E16777225/D16777225
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled
coroutine_pgsql => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
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 => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608

PHP

PHP 8.3.9 (cli) (built: Jul 23 2024 07:41:00) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.9, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.9, Copyright (c), by Zend Technologies

GCC

COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/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='Debian 12.2.0-14' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --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-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-12-bTRWOB/gcc-12-12.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-bTRWOB/gcc-12-12.2.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Debian 12.2.0-14)
NathanFreeman commented 2 months ago
$port2->on('connect', function (Server $server, $fd, $reactorId) use ($port2){
    var_dump($port2->setting);
});
grencik commented 1 month ago
$port2->on('connect', function (Server $server, $fd, $reactorId) use ($port2){
    var_dump($port2->setting);
});

True, I had it wrong. But still, when I set enable_delay_receive to true on $port2 it is ignored, until I set enable_delay_receive to true on $server. But I want to have different settings for different ports.

matyhtf commented 1 month ago

This option is a global setting and cannot be configured individually per port. After setting it, accepting connections will only trigger the onConnect event and will not receive data; must invoke Server::resume() to enable data reception.