Swoole\Coroutine\Http\Client->set

Declaration

<?php
Swoole\Coroutine\Http\Client->set(array $settings)

Parameters

settings

The array of settings

Return

Description

Update the settings of a HTTP Client.

Default settings

If there is no explict settings updated, the HTTP client uses the following default values:

<?php
[
    'method' => 'GET', // HTTP method
    'reconnect' => 1, // How many times to retry the connect if no success
    'timeout' => 0.5, // Connect timeout
    'defer' => false, // If defer the current request
    'keep_alive' => true, // If enable keep_alive
    'websocket_mask' => true, // If enable websocket mask
    'websocket_compression' => false, // If compress websocket messages
]

Example

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

Co\run(function() {
    $cli = new Client('127.0.0.1', 80);
    $cli->setHeaders([
        'Host' => "localhost",
        "User-Agent" => 'Chrome/49.0.2587.3',
        'Accept' => 'text/html,application/xhtml+xml,application/xml',
        'Accept-Encoding' => 'gzip',
    ]);
    $cli->set([ 'timeout' => 1]);
    $cli->get('/index.php');
    echo $cli->body;
    $cli->close();
});