Swoole\Coroutine\Http\Client->push

Declaration

<?php
Swoole\Coroutine\Http\Client->push(mixed $data, int $opcode = WEBSOCKET_OPCODE_TEXT, bool $finish = true)

Parameters

data

The data to be sent to the remote websocket server.

opcode

The opcode to be sent to the remote websocket server.

finish

Return

Description

Send data to the remote websocket server.

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->upgrade('/');
    $cli->push("websocket data\n");
    var_dump($cli->recv());
    $cli->close();
});