企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# Coroutine::readFile [TOC] 协程方式读取文件。 ~~~ function Coroutine::readFile(string $filename); ~~~ > 需要`2.1.2`或更高版本 ## 参数 * `$filename`文件名 ## 返回值 * 读取成功返回字符串内容,读取失败返回`false`,可使用`swoole_last_error`获取错误信息 * `readFile`方法没有尺寸限制,读取的内容会存放在内存中,因此读取超大文件时可能会占用过多内存 ## 示例 ~~~ use Swoole\Coroutine as co; $filename = __DIR__ . "/defer_client.php"; co::create(function () use ($filename) { $r = co::readFile($filename); var_dump($r); }); ~~~