OpenSwoole\Coroutine\Http\Client->getHeaders()

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\Coroutine\Http\Client->getHeaders(): array|bool

Parameters

None

Return

An array of key-value headers or false if something went wrong.


Description

Get the HTTP headers returned from the remote server during a request.


Example

<?php
use OpenSwoole\Coroutine\HTTP\Client;

co::run(function()
{
    $client = new Client('127.0.0.1', 80);

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

    $client->set(['timeout' => 1]);

    $client->setDefer(true);

    $client->get('/index.php');

    var_dump($client->getHeaders());

    $client->close();
});
Last updated on September 1, 2022