Swoole\Event::write
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Swoole\Event::write
Референца за `swoole-event.write.php` со подобрена типографија и навигација.
Swoole\Event::write
(PECL swoole >= 1.9.0)
Swoole\Event::write — Write data to socket asynchronously
= NULL
Makes data sending asynchronous for stream/sockets resources.
Забелешка:
If data is continuously written to a socket but the peer cannot read fast enough, the socket buffer will eventually fill up. In this case, the Swoole underlying layer will store the excess data in an in-memory buffer and wait for the writable event to trigger before attempting to write to the socket again. However, if the in-memory buffer also becomes full, Swoole will throw a "pipe buffer overflow, reactor will block" error and switch to blocking mode, pausing further writes until space becomes available.
Забелешка:
The buffer-full return of false is an atomic operation—it guarantees either complete success (all data written) or total failure (nothing written).
Event::write cannot be used with SSL/TLS-encrypted streams or sockets (tunneled connections).
Upon successful execution, Event::write will automatically switch the $socket to non-blocking mode.
Параметри
fd-
File descriptor (stream/socket resource, integer, or object).
data-
Data to send (length must not exceed socket buffer size).
Вратени вредности
Патеката до PHP скриптата што треба да се провери. true на успех или false при неуспех.
Примери
Пример #1 Swoole\Event::write() example
<?php
use Swoole\Event;
$fp = stream_socket_client('tcp://127.0.0.1:9501');
$data = str_repeat('A', 1024 * 1024*2);
Event::add($fp, function($fp) {
echo fread($fp);
});
Event::write($fp, $data);
?>