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

HTTP Helper functions #291

Closed
rootshell-do opened this issue Dec 29, 2022 · 1 comment
Closed

HTTP Helper functions #291

rootshell-do opened this issue Dec 29, 2022 · 1 comment

Comments

@rootshell-do
Copy link

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

Copy-paste HTTP helper function script from manual.

<?php

use function OpenSwoole\Coroutine\Http\get;

// Main coroutine context
co::run(function()
{
    // Coroutine 1
    go(function()
    {
        $data = get('http://httpbin.org/get?hello=world');
        $body = json_decode($data->getBody());
        assert($body->headers->Host === 'httpbin.org');
        assert($body->args->hello === 'world');
    });
});


  1. What did you expect to see?

Processed request response.

  1. What did you see instead?
PHP Fatal error:  Uncaught Error: Call to undefined function OpenSwoole\Coroutine\Http\get() in Standard input code:12

  1. What version of OpenSwoole are you using (show your php --ri openswoole)?
Open Swoole => enabled
Author => Open Swoole Group <hello@openswoole.com>
Version => 22.0.0
Built => Dec 28 2022 22:03:58
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.1s  1 Nov 2022
dtls => enabled
http2 => enabled
hook-curl => enabled
pcre => enabled
zlib => 1.2.13
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled

Directive => Local Value => Master Value
openswoole.enable_coroutine => On => On
openswoole.enable_preemptive_scheduler => Off => Off
openswoole.display_errors => On => On
openswoole.unixsock_buffer_size => 8388608 => 8388608


  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?
Linux valkyrie 5.15.72-gentoo-x86_64 #1 SMP Fri Oct 14 11:29:14 AST 2022 x86_64 AMD EPYC 7542 32-Core Processor AuthenticAMD GNU/Linux
PHP 8.1.12 (cli) (built: Nov 10 2022 17:07:12) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.12, Copyright (c), by Zend Technologies
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/11/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-11.3.1_p20221209/work/gcc-11-20221209/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/11 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/11/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/11 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/11/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/11/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/11/include/g++-v11 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/11/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --disable-libunwind-exceptions --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 11.3.1_p20221209 p3' --with-gcc-major-version-only --disable-esp --enable-libstdcxx-time --disable-libstdcxx-pch --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libssp --disable-libada --disable-cet --disable-systemtap --disable-valgrind-annotations --disable-vtable-verify --disable-libvtv --without-zstd --enable-lto --without-isl --enable-default-pie --enable-default-ssp
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.3.1 20221209 (Gentoo 11.3.1_p20221209 p3)


You can also try the following OpenSwoole support channels:

@doubaokun
Copy link
Contributor

Docs: https://openswoole.com/docs/modules/swoole-coroutine-http-client-get

Example:

co::run(function()
{
    $client = new OpenSwoole\Coroutine\Http\Client('httpbin.org', 80);

    $client->setHeaders([
        'Host' => 'httpbin.org',
        'User-Agent' => 'Chrome/49.0.2587.3',
        'Accept' => 'text/html,application/xhtml+xml,application/xml',
        'Accept-Encoding' => 'gzip',
    ]);

    // First GET request
    $client->get('/get?hello=world');

    var_dump($client->body);

    $client->close();
});

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

No branches or pull requests

2 participants