Swoole Server sendfile()

Declaration

<?php
Swoole\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');