phasync
Blocking calls and the extension / file_get_contents

Function

file_get_contents

Reads a whole file, letting other coroutines run while it waits.

Description#

function file_get_contents(
    string $filename
): string|false

Inside a coroutine, the file is read in 64 KiB chunks, waiting with phasync::readable() between them. Outside one, it is the native file_get_contents(). Unlike the native function it takes no other arguments, and it throws instead of returning false when the file cannot be opened.

Parameters#

$filename string
The file to read

Return values#

string|false

Errors / Exceptions#

ExceptionWhen
ExceptionWhen the file cannot be opened or a read fails

Examples#

Example 1
use function phasync\file_get_contents;

$config = file_get_contents(__DIR__ . '/config.json');

See also#