swoole之异步读写

//        异步读取文件内容
swoole_async_readfile(__DIR__."/1.txt", function($filename, $content) {
    echo "$filename: $content";
});

//异步写入文件

$file_content = '佛冷';
swoole_async_writefile(__DIR__.'/test.log', $file_content.PHP_EOL, function($filename) {
    echo $filename."wirte ok.\n";
}, FILE_APPEND);
//http_server中写入传来参数
$http->on('request', function ($request, $response) {
//    异步文件写入
        $file_content = [
            'data' => date('Y-m-d H:i:s'),
            'get' => $request->get,
            'post' => $request->post,
            'header' => $request->header,
        ];
        swoole_async_writefile(__DIR__.'/access.log', json_encode($file_content).PHP_EOL, function($filename) {
            echo $filename.":wirte ok.\n";
        }, FILE_APPEND);

    $response->end("love".json_encode($request->get));
});

浏览器访问时不需带静态文件

猜你喜欢

转载自blog.csdn.net/qq_40876291/article/details/84190911