Swoole\Coroutine\Http\Client->setDefer

Declaration

<?php
Swoole\Coroutine\Http\Client->setDefer(bool $defer = FALSE)

Parameters

defer

If the Client is in defer mode.

Return

Description

Set the client to be defer mode, allow the other coroutine request to execute when waiting the result.

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->setDefer(TRUE);
    $cli->get('/index.php');
    echo $cli->body;
    $cli->close();
});