Swoole (异步文件系统IO 读、 写)

set([
	'enable_static_handler' => true,
	'document_root' => '/Applications/MAMP/htdocs/swoole学习/swoole_demo/data'
]);

$http->on('request', function($request, $response) {

	// 日志记录
	$content = [
		'date:' => date('Ymd H:i:s'),
		'get:' => $request->get,
		'post:' => $request->post,
		'header:' => $request->header,
	];	
	// 异步日志记录
	swoole_saync_writefile(__DIR__ . '/access.log', json_encode($content) . PHP_EOL, function($filename) {
		
	}, FILE_APPEND);
	$response->cookie('mingzi', 'neirong', time() + 1800);
	$response->end(json_encode($request->get));
});

$http->start();




 

你可能感兴趣的:(swoole)