基于swoole4协程开发的高性能框架
- 上下文支持
- 已封装redis, mysql, celery-mq连接池
- 支持apollo配置
- docker的支持
git clone https://github.com/wjcgithub/dtsf.git
cd dtsf
composer install
docker pull wangjichao/dtsf_api
cd dtsf/docker
docker-compose up or docker-compose up -d
如果不需要apollo配置中心支持可先注释docker-compose中的
apollo_config
配置
浏览器访问 http://localhost:9505/index
$chan = new \chan(2);
$result = '';
$redis = RedisDefaultDao::getInstance();
$redis->setex('key1', 300, 'test-test-1');
$redis->setex('ket2', 300, 'test-test-2');
$result .= "redis get key1<br>" . PHP_EOL;
\Dtsf\Coroutine\Coroutine::create(function () use ($redis, $chan){
$val1 = $redis->get('key1');
$s1 = "redis key1 value: {$val1}<br>" . PHP_EOL;
$chan->push($s1);
});
$result .= "redis get key2<br>" . PHP_EOL;
\Dtsf\Coroutine\Coroutine::create(function () use ($redis, $chan){
$val2 = $redis->get('key1');
$s2 = "redis key2 value: {$val2}<br>" . PHP_EOL;
$chan->push($s2);
});
for ($i=0; $i<2; $i++) {
$result.=$chan->pop();
}
return "redis->end output <br> {$result}" . PHP_EOL;
上面代码已经在控制器中存在,直接访问 http://localhost:9501/redis/test即可看到如下输出