Swoole\Coroutine\Http\Client->getCookies()

4.x is outdated, please check the latest version 22.x


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Coroutine\Http\Client->getCookies(): array|bool

Parameters

None

Return

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


Description

Get the HTTP cookies returned from the remote server.

The cookie information will be decoded by urldecode. If you want to get the original cookie information, please parse it yourself according to the following: var_dump($client->set_cookie_headers).


Example

<?php
use Swoole\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->getCookies());

    $client->close();
});
Last updated on August 31, 2022