Swoole\Coroutine\Http\Client->get(...)

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->get(string $path): void

Parameters

path

The URL path to send a GET request to. For example /user/account or /index.php. Only set the path here not the protocol or domain name like http://domain.

Return

None


Description

Initiate a HTTP client GET request using the specified URL path.

When you use this method it will switch to use GET for you, no need to use setMethod


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',
    ]);

    // First GET request
    $client->get('/home/contact');

    var_dump($client->body);

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

    var_dump($client->body);

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