Menu

Reference / Async

writeFile()

function
function writeFile(string $path, string $data, int $chunk = 1048576): int

Write $data to a file in chunks, yielding to other tasks between them.

The same contract as readFile(). The file is created or truncated.

Parameters

$path string
the file to write
$data string
the contents
$chunk int = 1048576
bytes per write; default 1 MiB

Returns

int — the number of bytes written, or -1 when the file cannot be opened

Throws

CancelledException
when the task is cancelled between chunks

See also: readFile

View source