HEX
Server: Apache/2.4.59 (Debian)
System: Linux keymana 4.19.0-21-cloud-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64
User: lijunjie (1003)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/lijunjie/swoole-cli/swoole-src-4.8.13/examples/coroutine/http2_client.php
<?php
use Swoole\Coroutine as co;

const TEST = array('get', 'post', 'pipeline');
//const TEST = array('pipeline');
//const TEST = array('get',);

CO::set(['trace_flags' => SWOOLE_TRACE_HTTP2, 
// 'log_level' => SWOOLE_LOG_TRACE,



]);



co::create(function () use ($fp)
{
    $cli = new co\Http2\Client('127.0.0.1', 9518);

    $cli->set([ 'timeout' => 1, 'package_max_length' => 1024*1024*8]);
    var_dump($cli->connect());

    if (in_array('get', TEST))
    {
        $req = new Swoole\Http2\Request;
        $req->path = "/index.html";
        $req->headers = [
            'host' => "localhost",
            "user-agent" => 'Chrome/49.0.2587.3',
            'accept' => 'text/html,application/xhtml+xml,application/xml',
            'accept-encoding' => 'gzip',
        ];
        $req->cookies = ['name' => 'rango', 'email' => '1234@qq.com'];
        var_dump($cli->send($req));

        $resp = $cli->recv();
        var_dump($resp);
    }

    if (in_array('post', TEST))
    {
        $req2 = new Swoole\Http2\Request;
        $req2->path = "/index.php";
        $req2->headers = [
            'host' => "localhost",
            "user-agent" => 'Chrome/49.0.2587.3',
            'accept' => 'text/html,application/xhtml+xml,application/xml',
            'accept-encoding' => 'gzip',
        ];
        $req2->data = "hello world\n";
        var_dump($cli->send($req2));

        $resp = $cli->recv();
        var_dump($resp);
    }

    if (in_array('pipeline', TEST))
    {
        $req3 = new Swoole\Http2\Request;
        $req3->path = "/index.php";
        $req3->headers = [
            'host' => "localhost",
            "user-agent" => 'Chrome/49.0.2587.3',
            'accept' => 'text/html,application/xhtml+xml,application/xml',
            'accept-encoding' => 'gzip',
        ];
        $req3->pipeline = true;
        $req3->method = "POST";
        $streamId = $cli->send($req3);

        $cli->write($streamId, ['int' => rand(1000, 9999)]);
        $cli->write($streamId, ['int' => rand(1000, 9999)]);
        //end stream
        $cli->write($streamId, ['int' => rand(1000, 9999), 'end' => true], true);

        var_dump($cli->recv());
    }

//    $cli->close();
});