ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
# swoole\_async\_readfile [TOC] 异步读取文件内容,函数原型 ~~~ //函数风格 swoole_async_readfile(string $filename, mixed $callback); //命名空间风格 Swoole\Async::readFile(string $filename, mixed $callback); ~~~ * 文件不存在会返回`false` * 成功打开文件立即返回`true` * 数据读取完毕后会回调指定的`callback`函数。 ## 使用示例: ~~~ swoole_async_readfile(__DIR__."/server.php", function($filename, $content) { echo "$filename: $content"; }); ~~~ > `swoole_async_readfile`会将文件内容全部复制到内存,所以不能用于大文件的读取 > 如果要读取超大文件,请使用`swoole_async_read`函数 > `swoole_async_readfile`最大可读取`4M`的文件,受限于`SW_AIO_MAX_FILESIZE`宏