Swoole\Event->write

Declaration

<?php
Swoole\Event->write(int $fd, string $data)

Parameters

fd

fd of the socket

data

Data sending to the sock

Return

success

if success, it returns TRUE, otherwise it returns FALSE.

Description

Write data to the socket with async I/O.

Example

<?php
$fp = stream_socket_client('tcp://127.0.0.1:9501');
$data = str_repeat('A', 1024 * 1024 * 2);

Swoole\Event::add($fp, function($fp) {
     echo fread($fp);
});

Swoole\Event::write($fp, $data);