swoole非同期読み込みファイル、書き込みファイル
書き込み上限4 Mを読み出し、必要に応じてプロファイルを変更する必要があります
非同期読み込みファイル:swoole_async_readfile()
実行結果:
Is me The First?bool(true) filename:./swoole/project/swoole1/async/test.txt fileContent This a file Test This is The 2ed line.
非同期書き込みファイル:swoole_async_writefile()
実行結果:
is my 1st? bool(true) 2018-10-25 10:14:51/swoole/project/swoole1/asynclog.txtok
まとめ:非同期関数セクションは、今回の実行ファイルの最後に実行されますが、実行結果(成功または失敗)は事前に取得できます.
非同期でファイルを書き込み、いくつかの重要な操作に適用し、logログを記録し、非常に効率的で実用的です.
非同期読み込みファイル:swoole_async_readfile()
/** **/
//sleep(3);
$res = swoole_async_readfile(__DIR__."/test.txt",function($filename,$fileContent){
echo "filename:.$filename".PHP_EOL;
echo "fileContent".PHP_EOL;
echo $fileContent;
});
sleep(2);
echo "Is me The First?";
var_dump($res);
実行結果:
Is me The First?bool(true) filename:./swoole/project/swoole1/async/test.txt fileContent This a file Test This is The 2ed line.
非同期書き込みファイル:swoole_async_writefile()
$content = date("Y-m-d H:i:s",time()).PHP_EOL;
$res = swoole_async_writefile(__DIR__."/log.txt",$content,function($filename){
echo 'ok'.PHP_EOL;
},FILE_APPEND);
echo 'is my 1st?'.PHP_EOL;
var_dump($res);
echo $content;
echo __DIR__."log.txt";
実行結果:
is my 1st? bool(true) 2018-10-25 10:14:51/swoole/project/swoole1/asynclog.txtok
まとめ:非同期関数セクションは、今回の実行ファイルの最後に実行されますが、実行結果(成功または失敗)は事前に取得できます.
非同期でファイルを書き込み、いくつかの重要な操作に適用し、logログを記録し、非常に効率的で実用的です.