OpenSwoole Server sendfile()

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\Server->sendfile(int $fd, string $filename, int $offset = 0, int $length = 0): bool

Parameters

fd

The file descriptor of the client to send data to

filename

The path of file to send, if it does not exist false will be returned

offset

Specify the file offset, you can send data from a certain position of the file, default is 0 which means the whole of the file

length

Specify the length of the file to send, default is to send the whole of the file

Return

success

If success, it returns 'true', otherwise it returns false.

Description

Send large amounts of data or files to the remote TCP connection/socket.

Example

<?php
$server->sendfile($fd, __DIR__ . '/test.jpg');
Last updated on September 1, 2022