swoole tick example
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swoole tick example相关的知识,希望对你有一定的参考价值。
server:
$serv = new swoole_server(‘127.0.0.1‘, 9502);
$serv->on(‘receive‘, function ($serv, $fd, $from_id, $data) {
$serv->tick(3000, function() use($serv, $fd) {
$data = "tick-2000ms\n";
$serv->send($fd, $data);
});
});
$serv->start();
client:
$client = new Swoole_client(SWOOLE_SOCK_TCP,SWOOLE_SOCK_ASYNC); $client->connect(‘127.0.0.1‘, 9502, 1);
$cli->send(‘hehe‘);
});
$client->on("receive", function($cli, $data = ""){
if(empty($data)){
$cli->close();
echo "closed\n";
} else {
echo "received: $data\n";
sleep(1);
}
});
$client->on("close", function($cli){
echo "close\n";
});
本文出自 “我是程序我最大” 博客,请务必保留此出处http://skinglzw.blog.51cto.com/10729606/1963961
以上是关于swoole tick example的主要内容,如果未能解决你的问题,请参考以下文章
[Shell] swoole_timer_tick 与 crontab 实现定时任务和监控