Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\Coroutine\System::readFile(string $filename): string|false
The location of the file to read. Use an absolute filepath.
Returns string content as a whole when the file read is successful. When the file cannot be read or there is an error, false
is returned. Use OpenSwoole\Util::getLastErrorCode()
to get error information.
Read the whole contents of a file.
There is no size limit to this method, the content of the file will be read and stored into memory, large files will cause more memory to be used but this method is non-blocking to other workers or processes.
Note: Consider using coroutine hooks instead so you can easily use native PHP read and write functions.
<?php
co::run(function() use ($filename)
{
$filename = __DIR__ . "/test.txt";
$r = OpenSwoole\Coroutine::readFile($filename);
var_dump($r);
});