swoole 异步系统文件IO

https://wiki.swoole.com/wiki/page/183.html

一.读文件

//函数写法
//$result = swoole_async_readfile(__DIR__ . '/test.html', function ($filename, $fileContent) {
//命名空间写法
$result = Swoole\Async::readFile(__DIR__ . '/test.html', function ($filename, $fileContent) {
    echo 'filename:' . $filename . PHP_EOL;
    echo 'content:' . $fileContent . PHP_EOL;
});
print_r($result);
echo 'start' . PHP_EOL;

以上输出顺序

1.print_r($result);

2. echo 'start';

3.filename

4.content

二.写文件

/**
 * 写入文件
 * __DIR__
 * FILE_APPEND以追加的方式写入
 * 最在不可超过4M,超过4Mswoole_async_write
 */
$content = '这是我要写入的信息'. PHP_EOL;
$result = swoole_async_writefile(__DIR__ . '/test.html', $content, function ($filename) {
    echo 'write succ filename:' . $filename . PHP_EOL;
}, FILE_APPEND);

print_r($result);
echo 'start' . PHP_EOL;

猜你喜欢

转载自blog.csdn.net/zimuxin/article/details/80524514
今日推荐