<?php
// 创建tcp 服务器
$server = new swoole_server('0.0.0.0',2544);# 设置异步进程工作数
$server->set(array('task_worker_num'=>4,));# 投递异步任务
$server->on('receive',function ($ser,$fd,$from_id,$data){$task_id = $ser->task($data); # 异步idecho $task_id."\n";
});# 处理异步任务
$server->on('task',function ($ser,$task_id,$from_id,$data){echo '执行 异步ID'.$task_id;$ser->finish($data."-> ok\n");
});# 处理结果
$server->on('finish',function ($ser,$task_id,$data){echo '执行完成'."\n";
});$server->start();