swoole异步io操作

1.异步写入:

<?php

$content=date('Y-m-d H:i:s').PHP_EOL;

swoole_async_writefile(__DIR__.'/1.log',$content,function ($filename){
   // todo
    echo "文件名".$filename.':success'.PHP_EOL;
},FILE_APPEND);
echo "外部先执行:star".PHP_EOL;

2.异步读取:

$res=swoole_async_readfile(__DIR__ . '/1.txt',function ($filename, $fileContent){
    echo "filename:".$filename.PHP_EOL;
    echo "fileContent:".$fileContent.PHP_EOL;
    echo '内部start:'.time().PHP_EOL;//后执行
});
var_dump($res);
echo '外部start:'.time().PHP_EOL; //先执行

 

posted @ 2020-08-05 10:28  码农编程进阶笔记  阅读(37)  评论(0编辑  收藏  举报
返回顶部 有事您Q我