openswoole / ext-openswoole

Programmatic server for PHP with async IO, coroutines and fibers
https://openswoole.com
Apache License 2.0
808 stars 51 forks source link

HTTP client fails to make request when data contains empty array #267

Closed dompie closed 1 year ago

dompie commented 2 years ago
  1. What did you do? If possible, provide a simple script for reproducing the error.

    
    go(function () {
    $client = new Co\Http\Client('some.domain.com');
    $client->setData('');
    var_dump($client->execute('/first')); //true - getBody() returns response content
    
    $client->setData([]);
    var_dump($client->execute('/second')); //true - getBody() returns response content
    
    $client->setData(['data' => []]);
    var_dump($client->execute('/third')); //false - getBody() DOES NOT return response content
    //the request also fails with other methods than GET
    });
2. What did you expect to see?

No warning, a successful ->execute() and getBody() returning response content. The same behaviour as the /second request.


3. What did you see instead?

PHP Warning: Swoole\Coroutine\Http\Client::execute(): http_build_query failed in ... on line with execute('/third') statement

4. What version of OpenSwoole are you using (show your `php --ri openswoole`)?

openswoole

Open Swoole => enabled Author => Open Swoole Group hello@openswoole.com Version => 4.11.1 Built => Sep 22 2022 10:58:22 coroutine => enabled with boost asm context epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled openssl => OpenSSL 1.1.1f 31 Mar 2020 dtls => enabled http2 => enabled zlib => 1.2.11 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

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

Linux 5.15.0-48-generic #54~20.04.1-Ubuntu SMP Thu Sep 1 16:17:26 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux PHP 8.1.11 (cli) (built: Sep 29 2022 22:28:49) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.11, Copyright (c) Zend Technologies Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:hsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04.1' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --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 --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --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-9-Av3uEd/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)

doubaokun commented 1 year ago

It is as expected, postBody only accept array or empty like the API https://www.php.net/manual/en/function.http-build-query.php. It is recommend to use curl or coroutine curl and not HTTP client.