1.执行脚本的用 指令去执行 php swoole.php
2.定时任务的代码
<?php
$serv = new Swoole\Server("0.0.0.0", 9501);
$serv->set(array(
'worker_num' => 1, //worker process num
));
$serv->on('connect', function ($serv, $fd){
echo "客户端 ".$fd."连接成功 \n";
});
$serv->on('receive', function ($serv, $fd, $reactor_id, $data) {
echo "客户端 ".$fd."发来消息:".$data."\n";
$serv->send($fd, 'Swoole已经介绍到您发送的消息: '.$data);
});
$serv->on('close', function ($serv, $fd) {
echo "客户端 {$fd}关闭连接\n";
});
$serv->on('WorkerStart', function ($serv, $worker_id){
$serv->tick(2000, function(){
echo "我这是定时任务的 ".date("Y-m-d H:i:s",time())." \n";
});
});
$serv->start();
|